Hi, thanks for your reply
My problem is that the code generates a link based on the old style (previous to 1.7.5) of menu controller that doesn't use the Symfony based controller. So it assumes a [class_name]Controller.php file is in <module_name>/controller/admin/ . It doesn't allow me to specified the fully qualified class name or specify an action within that controller.
I have a controller that extends FrameworkBundleAdminController:
<?php namespace MyNamespace\Controller\Admin; use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; class MyDashboardController extends FrameworkBundleAdminController { /** Controller Code **/ public function dashboardAction() { return $this->render('@Modules/my_module/views/admin/dashboard.html.twig'); } }
I want to add a link in the admin side bar to the dashboard action of MyDashboardController.
the problem is that in my main module class where I create the tabs array like this:
<?php /** Somewhere in main module class constructor **/ $this->tabs = [ [ 'name' => [ 'en' => 'My Dashbord', 'fr' => 'Mon Table de bord', ], 'class_name' => 'MyDashboard', //Want to use: MyNamespace\Controllers\Admin\MyDashboardController:dashboardAction 'visible' => true, 'parent_class_name' => 'IMPROVE', ], ];
It won't work with the new way to develop modules based on the symfony system. The prestashop functions that register the tabs using the class_name element of the tabs array make the assumtion that the class_name is the old style, here is the code where it loads the class:
This is in /src/Adapter/Module/Tab/ModuleTabRegister.php[line:172].
We can see that the class name passed through the tabs array is used to concatenate to 'Controller.php' and then validated if it exists in the module admin controllers found, which looks in :
$modulePath = _PS_ROOT_DIR_ . '/' . basename(_PS_MODULE_DIR_) . '/' . $moduleName . '/controllers/admin/';
This is in /src/Adapter/Module/Tab/ModuleTabRegister.php:getModuleAdminControllers()[line:203].
This would not be so bad if I could also configure which action to use inside the controller, I could always reconfigure my module's PSR-4 autoloading to use the needed folder structure, but since I cannot say which action to use, the default run() function of the old style module controllers is called by default.
An ideal solutions would be to be able to pass MyNamespace\Controllers\Admin\MyDashboardController:dashboardAction to the tabs array class_name, this could easily be parsed to class name and method name by exploding the string on ":", A quick validation of class_exists could be done first and if so, execute the method of the class, if not go on and try the old style style loading.
Another better solution could be to pass the route that i configured in <my_module>/config/routes.yml. The tab loader would check the route configured which points to the correct controller and action:
my_dashbaord: path: my_module/dashboard methods: [GET] defaults: _controller: 'MyNamespace\Controller\Admin\MyDashboardController::dashboardAction'
Am I completely missing something here ? The way it is i don't see any way to implement an admin sidebar tab for a new module controller built using the official docs for 1.7.* that shows us to extend PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController and use custom namespaces?