From 2f7b0f466ab2ab175794446a9f504b67392863f1 Mon Sep 17 00:00:00 2001 From: Jonathan LELIEVRE Date: Mon, 28 Oct 2024 17:34:08 +0100 Subject: [PATCH 1/6] Refacto ShowcaseCardController based on PrestaShopAdminController --- .../Admin/Configure/ShowcaseCardController.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/PrestaShopBundle/Controller/Admin/Configure/ShowcaseCardController.php b/src/PrestaShopBundle/Controller/Admin/Configure/ShowcaseCardController.php index cfc6458989cd2..2d7fc5f55cc3c 100644 --- a/src/PrestaShopBundle/Controller/Admin/Configure/ShowcaseCardController.php +++ b/src/PrestaShopBundle/Controller/Admin/Configure/ShowcaseCardController.php @@ -30,17 +30,14 @@ use PrestaShop\PrestaShop\Core\Domain\ShowcaseCard\Command\CloseShowcaseCardCommand; use PrestaShop\PrestaShop\Core\Domain\ShowcaseCard\Exception\InvalidShowcaseCardNameException; use PrestaShop\PrestaShop\Core\Domain\ShowcaseCard\ValueObject\ShowcaseCard; -use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; +use PrestaShopBundle\Controller\Admin\PrestaShopAdminController; use PrestaShopBundle\Security\Attribute\AdminSecurity; use PrestaShopBundle\Security\Attribute\DemoRestricted; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -/** - * @todo Move this to API - */ -class ShowcaseCardController extends FrameworkBundleAdminController +class ShowcaseCardController extends PrestaShopAdminController { /** * Saves the user preference of closing the showcase card. @@ -55,7 +52,7 @@ class ShowcaseCardController extends FrameworkBundleAdminController */ #[DemoRestricted(redirectRoute: 'admin_metas_index')] #[AdminSecurity("is_granted('create', 'CONFIGURE') && is_granted('update', 'CONFIGURE')")] - public function closeShowcaseCardAction(Request $request) + public function closeShowcaseCardAction(Request $request): JsonResponse { // check prerequisites if (!$request->isMethod('post') || !$request->request->get('close')) { @@ -69,9 +66,8 @@ public function closeShowcaseCardAction(Request $request) } try { - $employeeId = $this->getContext()->employee->id; - $closeShowcaseCard = new CloseShowcaseCardCommand($employeeId, $request->request->get('name')); - $this->getCommandBus()->handle($closeShowcaseCard); + $closeShowcaseCard = new CloseShowcaseCardCommand($this->getEmployeeContext()->getEmployee()->getId(), $request->request->get('name')); + $this->dispatchCommand($closeShowcaseCard); return $this->json( [ From 06971e188c2acdeb1883b9644dd77f71481f891c Mon Sep 17 00:00:00 2001 From: Jonathan LELIEVRE Date: Mon, 28 Oct 2024 17:57:46 +0100 Subject: [PATCH 2/6] Refacto CommonController based on PrestaShopAdminController, introduce new type of service locator --- phpstan-disallowed-calls.neon | 1 + .../Factory/GridDefinitionFactoryProvider.php | 47 +++++++ .../Position/PositionDefinitionProvider.php | 47 +++++++ .../Controller/Admin/CommonController.php | 129 +++++++----------- .../Admin/PrestaShopAdminController.php | 5 +- .../Resources/config/services/bundle/grid.yml | 11 +- .../core/grid/grid_definition_factory.yml | 11 +- .../grid/grid_position_definition_factory.yml | 7 + .../Resources/config/services/core/kpi.yml | 9 +- ....php => PrestaShopAdminControllerTest.php} | 2 +- 10 files changed, 183 insertions(+), 86 deletions(-) create mode 100644 src/Core/Grid/Definition/Factory/GridDefinitionFactoryProvider.php create mode 100644 src/Core/Grid/Position/PositionDefinitionProvider.php rename tests/Integration/PrestaShopBundle/Controller/Admin/{FrameworkBundleAdminControllerTest.php => PrestaShopAdminControllerTest.php} (99%) diff --git a/phpstan-disallowed-calls.neon b/phpstan-disallowed-calls.neon index 9046289443a9a..af953844f93ec 100644 --- a/phpstan-disallowed-calls.neon +++ b/phpstan-disallowed-calls.neon @@ -285,6 +285,7 @@ parameters: disallowIn: - src/PrestaShopBundle/Controller/* allowIn: + - src/PrestaShopBundle/Controller/Admin/CommonController.php - src/PrestaShopBundle/Controller/Admin/FrameworkBundleAdminController.php - src/PrestaShopBundle/Controller/Admin/PrestaShopAdminController.php - src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAbstractController.php diff --git a/src/Core/Grid/Definition/Factory/GridDefinitionFactoryProvider.php b/src/Core/Grid/Definition/Factory/GridDefinitionFactoryProvider.php new file mode 100644 index 0000000000000..2904a40e92d13 --- /dev/null +++ b/src/Core/Grid/Definition/Factory/GridDefinitionFactoryProvider.php @@ -0,0 +1,47 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + */ + +namespace PrestaShop\PrestaShop\Core\Grid\Definition\Factory; + +use Symfony\Component\DependencyInjection\Attribute\AutowireLocator; +use Symfony\Contracts\Service\ServiceProviderInterface; + +/** + * This is a service locator that allows fetching grid definition factories via their index. + */ +class GridDefinitionFactoryProvider +{ + public function __construct( + #[AutowireLocator('core.grid_definition_factory')] + protected ServiceProviderInterface $factories + ) { + } + + public function getFactory(string $name): GridDefinitionFactoryInterface + { + return $this->factories->get($name); + } +} diff --git a/src/Core/Grid/Position/PositionDefinitionProvider.php b/src/Core/Grid/Position/PositionDefinitionProvider.php new file mode 100644 index 0000000000000..b9ca56830ace1 --- /dev/null +++ b/src/Core/Grid/Position/PositionDefinitionProvider.php @@ -0,0 +1,47 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + */ + +namespace PrestaShop\PrestaShop\Core\Grid\Position; + +use Symfony\Component\DependencyInjection\Attribute\AutowireLocator; +use Symfony\Contracts\Service\ServiceProviderInterface; + +/** + * This is a service locator that allows fetching position definitions via their index. + */ +class PositionDefinitionProvider +{ + public function __construct( + #[AutowireLocator('core.grid_position_definition')] + protected ServiceProviderInterface $positionDefinitions + ) { + } + + public function getPositionDefinition(string $name): PositionDefinitionInterface + { + return $this->positionDefinitions->get($name); + } +} diff --git a/src/PrestaShopBundle/Controller/Admin/CommonController.php b/src/PrestaShopBundle/Controller/Admin/CommonController.php index 97d3c0ed09235..ae9cf368feba5 100644 --- a/src/PrestaShopBundle/Controller/Admin/CommonController.php +++ b/src/PrestaShopBundle/Controller/Admin/CommonController.php @@ -26,23 +26,20 @@ namespace PrestaShopBundle\Controller\Admin; -use Context; use PrestaShop\PrestaShop\Adapter\Tools; use PrestaShop\PrestaShop\Core\Domain\Notification\Command\UpdateEmployeeNotificationLastElementCommand; use PrestaShop\PrestaShop\Core\Domain\Notification\Query\GetNotificationLastElements; use PrestaShop\PrestaShop\Core\Domain\Notification\QueryResult\NotificationsResults; use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory; use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\FilterableGridDefinitionFactoryInterface; -use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\GridDefinitionFactoryInterface; +use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\GridDefinitionFactoryProvider; use PrestaShop\PrestaShop\Core\Grid\Position\Exception\PositionUpdateException; -use PrestaShop\PrestaShop\Core\Grid\Position\GridPositionUpdaterInterface; -use PrestaShop\PrestaShop\Core\Grid\Position\PositionDefinitionInterface; -use PrestaShop\PrestaShop\Core\Grid\Position\PositionUpdateFactoryInterface; +use PrestaShop\PrestaShop\Core\Grid\Position\PositionDefinitionProvider; use PrestaShop\PrestaShop\Core\Kpi\Row\KpiRowInterface; -use PrestaShopBundle\Entity\Employee\Employee; +use PrestaShop\PrestaShop\Core\Kpi\Row\KpiRowPresenter; +use PrestaShopBundle\Entity\Repository\AdminFilterRepository; use PrestaShopBundle\Security\Attribute\AdminSecurity; use PrestaShopBundle\Service\Grid\ControllerResponseBuilder; -use PrestaShopBundle\Service\Grid\ResponseBuilder; use ReflectionClass; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -52,8 +49,15 @@ /** * Admin controller for the common actions across the whole admin interface. */ -class CommonController extends FrameworkBundleAdminController +class CommonController extends PrestaShopAdminController { + public static function getSubscribedServices(): array + { + return parent::getSubscribedServices() + [ + ControllerResponseBuilder::class => ControllerResponseBuilder::class, + ]; + } + /** * Get a summary of recent events on the shop. * This includes: @@ -63,11 +67,10 @@ class CommonController extends FrameworkBundleAdminController * * @return JsonResponse */ - public function notificationsAction() + public function notificationsAction(): JsonResponse { - $employeeId = Context::getContext()->employee->id; /** @var NotificationsResults $elements */ - $elements = $this->getQueryBus()->handle(new GetNotificationLastElements($employeeId)); + $elements = $this->dispatchQuery(new GetNotificationLastElements($this->getEmployeeContext()->getEmployee()->getId())); return new JsonResponse($elements->getNotificationsResultsForJS()); } @@ -79,10 +82,9 @@ public function notificationsAction() * * @return JsonResponse */ - public function notificationsAckAction(Request $request) + public function notificationsAckAction(Request $request): JsonResponse { - $type = $request->request->get('type'); - $this->getCommandBus()->handle(new UpdateEmployeeNotificationLastElementCommand($type)); + $this->dispatchCommand(new UpdateEmployeeNotificationLastElementCommand($request->request->get('type'))); return new JsonResponse(true); } @@ -112,7 +114,7 @@ public function notificationsAckAction(Request $request) * * @return Response */ - public function paginationAction(Request $request, $limit = 10, $offset = 0, $total = 0, $view = 'full', $prefix = ''): Response + public function paginationAction(Request $request, ?int $limit = 10, ?int $offset = 0, ?int $total = 0, string $view = 'full', string $prefix = ''): Response { $offsetParam = empty($prefix) ? 'offset' : sprintf('%s[offset]', $prefix); $limitParam = empty($prefix) ? 'limit' : sprintf('%s[limit]', $prefix); @@ -210,10 +212,12 @@ public function paginationAction(Request $request, $limit = 10, $offset = 0, $to * * @return Response */ - public function renderSidebarAction($url, $title = '', $footer = '') - { - $tools = $this->get(Tools::class); - + public function renderSidebarAction( + Tools $tools, + string $url, + string $title = '', + string $footer = '', + ): Response { return $this->render('@PrestaShop/Admin/Common/_partials/_sidebar.html.twig', [ 'footer' => $tools->purifyHTML($footer), 'title' => $title, @@ -228,12 +232,12 @@ public function renderSidebarAction($url, $title = '', $footer = '') * * @return Response */ - public function renderKpiRowAction(KpiRowInterface $kpiRow) - { - $presenter = $this->get('prestashop.core.kpi_row.presenter'); - + public function renderKpiRowAction( + KpiRowInterface $kpiRow, + KpiRowPresenter $kpiRowPresenter, + ): Response { return $this->render('@PrestaShop/Admin/Common/Kpi/kpi_row.html.twig', [ - 'kpiRow' => $presenter->present($kpiRow), + 'kpiRow' => $kpiRowPresenter->present($kpiRow), ]); } @@ -246,11 +250,14 @@ public function renderKpiRowAction(KpiRowInterface $kpiRow) * * @throws \Doctrine\ORM\OptimisticLockException */ - public function resetSearchAction($controller = '', $action = '', $filterId = '') - { - $adminFiltersRepository = $this->get('prestashop.core.admin.admin_filter.repository'); - $employeeId = $this->getUser() instanceof Employee ? $this->getUser()->getId() : 0; - $shopId = $this->getContext()->shop->id; + public function resetSearchAction( + AdminFilterRepository $adminFiltersRepository, + string $controller = '', + string $action = '', + string $filterId = '', + ): JsonResponse { + $employeeId = $this->getEmployeeContext()->getEmployee()->getId(); + $shopId = $this->getShopContext()->getId(); // for compatibility when $controller and $action are used if (!empty($controller) && !empty($action)) { @@ -270,33 +277,6 @@ public function resetSearchAction($controller = '', $action = '', $filterId = '' return new JsonResponse(); } - /** - * Specific action to render a specific field twice. - * - * @param string $formName the form name - * @param string $formType the form type FQCN - * @param string $fieldName the field name - * @param array $fieldData the field data - * - * @return Response - */ - public function renderFieldAction($formName, $formType, $fieldName, $fieldData) - { - $formData = [ - $formName => [ - $fieldName => $fieldData, - ], - ]; - - $form = $this->createFormBuilder($formData); - $form->add($formName, $formType); - - return $this->render('@PrestaShop/Admin/Common/_partials/_form_field.html.twig', [ - 'form' => $form->getForm()->get($formName)->get($fieldName)->createView(), - 'formId' => $formName . '_' . $fieldName . '_rendered', - ]); - } - /** * Process Grid search. * @@ -309,16 +289,15 @@ public function renderFieldAction($formName, $formType, $fieldName, $fieldData) */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller'))")] public function searchGridAction( + GridDefinitionFactoryProvider $gridDefinitionFactoryCollection, Request $request, - $gridDefinitionFactoryServiceId, - $redirectRoute, + string $gridDefinitionFactoryServiceId, + string $redirectRoute, array $redirectQueryParamsToKeep = [] ) { - /** @var GridDefinitionFactoryInterface $definitionFactory */ - $definitionFactory = $this->get($gridDefinitionFactoryServiceId); + $definitionFactory = $gridDefinitionFactoryCollection->getFactory($gridDefinitionFactoryServiceId); $filterId = null; - if ($definitionFactory instanceof FilterableGridDefinitionFactoryInterface) { $filterId = $definitionFactory->getFilterId(); } elseif ($definitionFactory instanceof AbstractGridDefinitionFactory) { @@ -332,21 +311,18 @@ public function searchGridAction( } if (null !== $filterId) { - /** @var ResponseBuilder $responseBuilder */ - $responseBuilder = $this->get('prestashop.bundle.grid.response_builder'); - - return $responseBuilder->buildSearchResponse( + return $this->buildSearchResponse( $definitionFactory, $request, $filterId, $redirectRoute, - $redirectQueryParamsToKeep + $redirectQueryParamsToKeep, ); } // Legacy grid definition which use controller/action as filter keys (and no scope for parameters) /** @var ControllerResponseBuilder $controllerResponseBuilder */ - $controllerResponseBuilder = $this->get('prestashop.bundle.grid.controller_response_builder'); + $controllerResponseBuilder = $this->container->get(ControllerResponseBuilder::class); return $controllerResponseBuilder->buildSearchResponse( $definitionFactory, @@ -362,24 +338,21 @@ public function searchGridAction( * @return RedirectResponse */ #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))")] - public function updatePositionAction(Request $request): RedirectResponse - { + public function updatePositionAction( + Request $request, + PositionDefinitionProvider $positionDefinitionProvider, + ): RedirectResponse { $positionsData = [ 'positions' => $request->request->all('positions'), ]; - /** @var PositionDefinitionInterface $positionDefinition */ - $positionDefinition = $this->get($request->attributes->get('position_definition')); - $positionUpdateFactory = $this->get(PositionUpdateFactoryInterface::class); - + $positionDefinition = $positionDefinitionProvider->getPositionDefinition($request->attributes->get('position_definition')); try { - $positionUpdate = $positionUpdateFactory->buildPositionUpdate($positionsData, $positionDefinition); - $updater = $this->get(GridPositionUpdaterInterface::class); - $updater->update($positionUpdate); - $this->addFlash('success', $this->trans('Successful update', 'Admin.Notifications.Success')); + $this->updateGridPosition($positionDefinition, $positionsData); + $this->addFlash('success', $this->trans('Successful update', [], 'Admin.Notifications.Success')); } catch (PositionUpdateException $e) { $errors = [$e->toArray()]; - $this->flashErrors($errors); + $this->addFlashErrors($errors); } return $this->redirectToRoute($request->attributes->get('redirect_route')); diff --git a/src/PrestaShopBundle/Controller/Admin/PrestaShopAdminController.php b/src/PrestaShopBundle/Controller/Admin/PrestaShopAdminController.php index ecaa480798f34..3f26389d59d34 100644 --- a/src/PrestaShopBundle/Controller/Admin/PrestaShopAdminController.php +++ b/src/PrestaShopBundle/Controller/Admin/PrestaShopAdminController.php @@ -44,6 +44,7 @@ use PrestaShop\PrestaShop\Core\Grid\GridInterface; use PrestaShop\PrestaShop\Core\Grid\Position\GridPositionUpdaterInterface; use PrestaShop\PrestaShop\Core\Grid\Position\PositionDefinition; +use PrestaShop\PrestaShop\Core\Grid\Position\PositionDefinitionInterface; use PrestaShop\PrestaShop\Core\Grid\Position\PositionUpdateFactoryInterface; use PrestaShop\PrestaShop\Core\Grid\Presenter\GridPresenterInterface; use PrestaShop\PrestaShop\Core\Help\Documentation; @@ -324,7 +325,7 @@ protected function buildSearchResponse( /** * Updates the position of a grid based on the provided PositionDefinition and provided data. * - * @param PositionDefinition $positionDefinition + * @param PositionDefinitionInterface $positionDefinition * @param array $positionsData * * @return void @@ -332,7 +333,7 @@ protected function buildSearchResponse( * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - protected function updateGridPosition(PositionDefinition $positionDefinition, array $positionsData): void + protected function updateGridPosition(PositionDefinitionInterface $positionDefinition, array $positionsData): void { $positionUpdateFactory = $this->container->get(PositionUpdateFactoryInterface::class); $positionUpdate = $positionUpdateFactory->buildPositionUpdate($positionsData, $positionDefinition); diff --git a/src/PrestaShopBundle/Resources/config/services/bundle/grid.yml b/src/PrestaShopBundle/Resources/config/services/bundle/grid.yml index 3009d34e4c947..7e1e0619ec608 100644 --- a/src/PrestaShopBundle/Resources/config/services/bundle/grid.yml +++ b/src/PrestaShopBundle/Resources/config/services/bundle/grid.yml @@ -19,8 +19,15 @@ services: package: PrestaShop\PrestaShop version: 9.0 - prestashop.bundle.grid.controller_response_builder: - class: PrestaShopBundle\Service\Grid\ControllerResponseBuilder + PrestaShopBundle\Service\Grid\ControllerResponseBuilder: + public: false arguments: - '@prestashop.core.grid.filter.form_factory' - '@router' + + prestashop.bundle.grid.controller_response_builder: + alias: PrestaShopBundle\Service\Grid\ControllerResponseBuilder + public: true + deprecated: + package: PrestaShop\PrestaShop + version: 9.0 diff --git a/src/PrestaShopBundle/Resources/config/services/core/grid/grid_definition_factory.yml b/src/PrestaShopBundle/Resources/config/services/core/grid/grid_definition_factory.yml index 1cd214dc667ab..c943fc196e33a 100644 --- a/src/PrestaShopBundle/Resources/config/services/core/grid/grid_definition_factory.yml +++ b/src/PrestaShopBundle/Resources/config/services/core/grid/grid_definition_factory.yml @@ -1,9 +1,16 @@ services: _defaults: public: true + _instanceof: + PrestaShop\PrestaShop\Core\Grid\Definition\Factory\GridDefinitionFactoryInterface: + tags: [ 'core.grid_definition_factory' ] + + PrestaShop\PrestaShop\Core\Grid\Definition\Factory\GridDefinitionFactoryProvider: + arguments: + $factories: !tagged_locator { tag: core.grid_definition_factory } PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory: - abstract: true + public: false arguments: - '@prestashop.core.hook.dispatcher' calls: @@ -477,7 +484,7 @@ services: # Alias for this abstract definition causes tests in vendor fail for some reason, so we stick to full definition instead prestashop.core.grid.definition.factory.abstract_grid_definition: class: 'PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory' - abstract: true + public: false arguments: - '@prestashop.core.hook.dispatcher' calls: diff --git a/src/PrestaShopBundle/Resources/config/services/core/grid/grid_position_definition_factory.yml b/src/PrestaShopBundle/Resources/config/services/core/grid/grid_position_definition_factory.yml index 515664514de97..9ae1262109e2c 100644 --- a/src/PrestaShopBundle/Resources/config/services/core/grid/grid_position_definition_factory.yml +++ b/src/PrestaShopBundle/Resources/config/services/core/grid/grid_position_definition_factory.yml @@ -1,6 +1,13 @@ services: _defaults: public: true + _instanceof: + PrestaShop\PrestaShop\Core\Grid\Position\PositionDefinitionInterface: + tags: [ 'core.grid_position_definition' ] + + PrestaShop\PrestaShop\Core\Grid\Position\PositionDefinitionProvider: + arguments: + $positionDefinitions: !tagged_locator { tag: core.grid_position_definition } prestashop.core.grid.cms_page_category.position_definition: class: 'PrestaShop\PrestaShop\Core\Grid\Position\PositionDefinition' diff --git a/src/PrestaShopBundle/Resources/config/services/core/kpi.yml b/src/PrestaShopBundle/Resources/config/services/core/kpi.yml index 6ec0f73a79880..214c8a68389bd 100644 --- a/src/PrestaShopBundle/Resources/config/services/core/kpi.yml +++ b/src/PrestaShopBundle/Resources/config/services/core/kpi.yml @@ -3,8 +3,15 @@ services: public: true # KPI Row presenter + PrestaShop\PrestaShop\Core\Kpi\Row\KpiRowPresenter: + public: false + prestashop.core.kpi_row.presenter: - class: PrestaShop\PrestaShop\Core\Kpi\Row\KpiRowPresenter + alias: PrestaShop\PrestaShop\Core\Kpi\Row\KpiRowPresenter + public: true + deprecated: + package: PrestaShop\PrestaShop + version: 9.0 # KPI Row factories prestashop.core.kpi_row.factory.translations_page: diff --git a/tests/Integration/PrestaShopBundle/Controller/Admin/FrameworkBundleAdminControllerTest.php b/tests/Integration/PrestaShopBundle/Controller/Admin/PrestaShopAdminControllerTest.php similarity index 99% rename from tests/Integration/PrestaShopBundle/Controller/Admin/FrameworkBundleAdminControllerTest.php rename to tests/Integration/PrestaShopBundle/Controller/Admin/PrestaShopAdminControllerTest.php index 2edcd41ae8c20..29ac5ffe64c4b 100644 --- a/tests/Integration/PrestaShopBundle/Controller/Admin/FrameworkBundleAdminControllerTest.php +++ b/tests/Integration/PrestaShopBundle/Controller/Admin/PrestaShopAdminControllerTest.php @@ -32,7 +32,7 @@ use Tests\Integration\Utility\LoginTrait; use Tests\TestCase\SymfonyIntegrationTestCase; -class FrameworkBundleAdminControllerTest extends SymfonyIntegrationTestCase +class PrestaShopAdminControllerTest extends SymfonyIntegrationTestCase { use LoginTrait; From 084ec590e58ebe33e94b211062e3f447bd64c43f Mon Sep 17 00:00:00 2001 From: Jonathan LELIEVRE Date: Tue, 29 Oct 2024 01:55:57 +0100 Subject: [PATCH 3/6] Refacto ThemeController based on PrestaShopAdminController --- .../Admin/Improve/Design/ThemeController.php | 193 ++++++++---------- .../config/services/adapter/language.yml | 11 +- .../Resources/config/services/core/addon.yml | 32 ++- 3 files changed, 123 insertions(+), 113 deletions(-) diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Design/ThemeController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Design/ThemeController.php index 068021dbab312..51ff330d21ee8 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Design/ThemeController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Design/ThemeController.php @@ -27,6 +27,10 @@ namespace PrestaShopBundle\Controller\Admin\Improve\Design; use Exception; +use PrestaShop\PrestaShop\Adapter\Language\RTL\InstalledLanguageChecker; +use PrestaShop\PrestaShop\Core\Addon\Theme\ThemeExporter; +use PrestaShop\PrestaShop\Core\Addon\Theme\ThemePageLayoutsCustomizer; +use PrestaShop\PrestaShop\Core\Addon\Theme\ThemeProvider; use PrestaShop\PrestaShop\Core\Domain\Exception\DomainException; use PrestaShop\PrestaShop\Core\Domain\Exception\FileUploadException; use PrestaShop\PrestaShop\Core\Domain\Meta\Query\GetPagesForLayoutCustomization; @@ -53,11 +57,13 @@ use PrestaShop\PrestaShop\Core\Domain\Theme\ValueObject\ThemeName; use PrestaShop\PrestaShop\Core\Form\FormHandlerInterface; use PrestaShop\PrestaShop\Core\Security\Permission; -use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController as AbstractAdminController; +use PrestaShopBundle\Controller\Admin\PrestaShopAdminController; use PrestaShopBundle\Form\Admin\Improve\Design\Theme\AdaptThemeToRTLLanguagesType; use PrestaShopBundle\Form\Admin\Improve\Design\Theme\ImportThemeType; +use PrestaShopBundle\Form\Admin\Improve\Design\Theme\PageLayoutCustomizationFormFactory; use PrestaShopBundle\Security\Attribute\AdminSecurity; use PrestaShopBundle\Security\Attribute\DemoRestricted; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -67,7 +73,7 @@ /** * Class ThemeController manages "Improve > Design > Theme & Logo" pages. */ -class ThemeController extends AbstractAdminController +class ThemeController extends PrestaShopAdminController { /** * Show main themes page. @@ -77,16 +83,19 @@ class ThemeController extends AbstractAdminController * @return Response */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller'))", message: 'You do not have permission to edit this.')] - public function indexAction(Request $request) - { - $themeProvider = $this->get('prestashop.core.addon.theme.theme_provider'); - $installedRtlLanguageChecker = $this->get('prestashop.adapter.language.rtl.installed_language_checker'); + public function indexAction( + Request $request, + ThemeProvider $themeProvider, + InstalledLanguageChecker $installedRtlLanguageChecker, + #[Autowire(service: 'prestashop.admin.shop_logos_settings.form_handler')] + FormHandlerInterface $logosUploadFormHandler, + ): Response { /** @var LogosPaths $logoProvider */ - $logoProvider = $this->getQueryBus()->handle(new GetLogosPaths()); + $logoProvider = $this->dispatchQuery(new GetLogosPaths()); return $this->render('@PrestaShop/Admin/Improve/Design/Theme/index.html.twig', [ - 'baseShopUrl' => $this->get('prestashop.adapter.shop.url.base_url_provider')->getUrl(), - 'shopLogosForm' => $this->getLogosUploadForm()->createView(), + 'baseShopUrl' => $this->getShopContext()->getBaseURL(), + 'shopLogosForm' => $logosUploadFormHandler->getForm()->createView(), 'headerLogoPath' => $logoProvider->getHeaderLogoPath(), 'mailLogoPath' => $logoProvider->getMailLogoPath(), 'invoiceLogoPath' => $logoProvider->getInvoiceLogoPath(), @@ -94,11 +103,11 @@ public function indexAction(Request $request) 'currentlyUsedTheme' => $themeProvider->getCurrentlyUsedTheme(), 'notUsedThemes' => $themeProvider->getNotUsedThemes(), 'isDevModeOn' => $this->getConfiguration()->get('_PS_MODE_DEV_'), - 'isSingleShopContext' => $this->get('prestashop.adapter.shop.context')->isSingleShopContext(), - 'isMultiShopFeatureUsed' => $this->get('prestashop.adapter.multistore_feature')->isUsed(), + 'isSingleShopContext' => $this->getShopContext()->getShopConstraint()->isSingleShopContext(), + 'isMultiShopFeatureUsed' => $this->getShopContext()->isMultiShopUsed(), 'adaptThemeToRtlLanguagesForm' => $this->getAdaptThemeToRtlLanguageForm()->createView(), 'isInstalledRtlLanguage' => $installedRtlLanguageChecker->isInstalledRtlLanguage(), - 'shopName' => $this->get('prestashop.adapter.shop.context')->getShopName(), + 'shopName' => $this->getShopContext()->getName(), 'enableSidebar' => true, 'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')), ]); @@ -113,19 +122,22 @@ public function indexAction(Request $request) */ #[DemoRestricted(redirectRoute: 'admin_themes_index')] #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_themes_index')] - public function uploadLogosAction(Request $request) - { - $logosUploadForm = $this->getLogosUploadForm(); + public function uploadLogosAction( + Request $request, + #[Autowire(service: 'prestashop.admin.shop_logos_settings.form_handler')] + FormHandlerInterface $logosUploadFormHandler, + ): RedirectResponse { + $logosUploadForm = $logosUploadFormHandler->getForm(); $logosUploadForm->handleRequest($request); if ($logosUploadForm->isSubmitted()) { $data = $logosUploadForm->getData(); try { - $this->getShopLogosFormHandler()->save($data); + $logosUploadFormHandler->save($data); $this->addFlash( 'success', - $this->trans('The settings have been successfully updated.', 'Admin.Notifications.Success') + $this->trans('The settings have been successfully updated.', [], 'Admin.Notifications.Success') ); } catch (DomainException $e) { $this->addFlash( @@ -148,19 +160,18 @@ public function uploadLogosAction(Request $request) */ #[DemoRestricted(redirectRoute: 'admin_themes_index')] #[AdminSecurity("is_granted('create', request.get('_legacy_controller'))", redirectRoute: 'admin_themes_index', message: 'You do not have permission to view this.')] - public function exportAction() - { - $themeProvider = $this->get('prestashop.core.addon.theme.theme_provider'); - $exporter = $this->get('prestashop.core.addon.theme.exporter'); - - $path = $exporter->export($themeProvider->getCurrentlyUsedTheme()); + public function exportAction( + ThemeProvider $themeProvider, + ThemeExporter $themeExporter, + ): RedirectResponse { + $path = $themeExporter->export($themeProvider->getCurrentlyUsedTheme()); $this->addFlash( 'success', $this->trans( 'Your theme has been correctly exported: %path%', + ['%path%' => $path], 'Admin.Notifications.Success', - ['%path%' => $path] ) ); @@ -176,7 +187,7 @@ public function exportAction() */ #[DemoRestricted(redirectRoute: 'admin_themes_index')] #[AdminSecurity("is_granted('create', request.get('_legacy_controller'))", redirectRoute: 'admin_themes_index', message: 'You do not have permission to add this.')] - public function importAction(Request $request) + public function importAction(Request $request): Response { $importThemeForm = $this->createForm(ImportThemeType::class); $importThemeForm->handleRequest($request); @@ -197,13 +208,13 @@ public function importAction(Request $request) if (null === $importSource) { $this->addFlash( 'warning', - $this->trans('Please select theme\'s import source.', 'Admin.Notifications.Warning') + $this->trans('Please select theme\'s import source.', [], 'Admin.Notifications.Warning') ); return $this->redirectToRoute('admin_themes_import'); } - $this->getCommandBus()->handle(new ImportThemeCommand($importSource)); + $this->dispatchCommand(new ImportThemeCommand($importSource)); return $this->redirectToRoute('admin_themes_index'); } catch (ThemeException $e) { @@ -221,7 +232,7 @@ public function importAction(Request $request) return $this->render('@PrestaShop/Admin/Improve/Design/Theme/import.html.twig', [ 'importThemeForm' => $importThemeForm->createView(), - 'layoutTitle' => $this->trans('Theme import', 'Admin.Navigation.Menu'), + 'layoutTitle' => $this->trans('Theme import', [], 'Admin.Navigation.Menu'), ]); } @@ -234,11 +245,11 @@ public function importAction(Request $request) */ #[DemoRestricted(redirectRoute: 'admin_themes_index')] #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_themes_index', message: 'You do not have permission to edit this.')] - public function enableAction($themeName) + public function enableAction(string $themeName): RedirectResponse { try { - $this->getCommandBus()->handle(new EnableThemeCommand(new ThemeName($themeName))); - $this->addFlash('success', $this->trans('Successful update', 'Admin.Notifications.Success')); + $this->dispatchCommand(new EnableThemeCommand(new ThemeName($themeName))); + $this->addFlash('success', $this->trans('Successful update', [], 'Admin.Notifications.Success')); } catch (ThemeException $e) { $this->addFlash( 'error', @@ -263,14 +274,14 @@ public function enableAction($themeName) */ #[DemoRestricted(redirectRoute: 'admin_themes_index')] #[AdminSecurity("is_granted('delete', request.get('_legacy_controller'))", redirectRoute: 'admin_themes_index', message: 'You do not have permission to delete this.')] - public function deleteAction($themeName) + public function deleteAction(string $themeName): RedirectResponse { try { - $this->getCommandBus()->handle(new DeleteThemeCommand(new ThemeName($themeName))); + $this->dispatchCommand(new DeleteThemeCommand(new ThemeName($themeName))); $this->addFlash( 'success', - $this->trans('Successful deletion', 'Admin.Notifications.Success') + $this->trans('Successful deletion', [], 'Admin.Notifications.Success') ); } catch (ThemeException $e) { $this->addFlash('error', $this->handleDeleteThemeException($e)); @@ -290,7 +301,7 @@ public function deleteAction($themeName) */ #[DemoRestricted(redirectRoute: 'admin_themes_index')] #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_themes_index', message: 'You do not have permission to edit this.')] - public function adaptToRTLLanguagesAction(Request $request) + public function adaptToRTLLanguagesAction(Request $request): RedirectResponse { $form = $this->getAdaptThemeToRtlLanguageForm(); $form->handleRequest($request); @@ -306,13 +317,13 @@ public function adaptToRTLLanguagesAction(Request $request) } try { - $this->getCommandBus()->handle(new AdaptThemeToRTLLanguagesCommand( + $this->dispatchCommand(new AdaptThemeToRTLLanguagesCommand( new ThemeName($data['theme_to_adapt']) )); $this->addFlash( 'success', - $this->trans('Your RTL stylesheets has been generated successfully', 'Admin.Design.Notification') + $this->trans('Your RTL stylesheets has been generated successfully', [], 'Admin.Design.Notification') ); } catch (ThemeException $e) { $this->addFlash('error', $this->handleAdaptThemeToRTLLanguagesException($e)); @@ -330,16 +341,16 @@ public function adaptToRTLLanguagesAction(Request $request) */ #[DemoRestricted(redirectRoute: 'admin_themes_index')] #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_themes_index', message: 'You do not have permission to edit this.')] - public function resetLayoutsAction($themeName) + public function resetLayoutsAction(string $themeName): RedirectResponse { - $this->getCommandBus()->handle(new ResetThemeLayoutsCommand(new ThemeName($themeName))); + $this->dispatchCommand(new ResetThemeLayoutsCommand(new ThemeName($themeName))); $this->addFlash('success', $this->trans( 'Your theme has been correctly reset to its default settings. You may want to regenerate your images. See the Improve > Design > Images Settings screen for the \'%regenerate_label%\' button.', - 'Admin.Design.Notification', [ - '%regenerate_label%' => $this->trans('Regenerate thumbnails', 'Admin.Design.Feature'), - ] + '%regenerate_label%' => $this->trans('Regenerate thumbnails', [], 'Admin.Design.Feature'), + ], + 'Admin.Design.Notification', )); return $this->redirectToRoute('admin_themes_index'); @@ -352,22 +363,23 @@ public function resetLayoutsAction($themeName) * * @return Response */ - public function customizeLayoutsAction(Request $request) - { + public function customizeLayoutsAction( + Request $request, + PageLayoutCustomizationFormFactory $pageLayoutCustomizationFormFactory, + ThemePageLayoutsCustomizer $themePageLayoutsCustomizer, + ): Response { $canCustomizeLayout = $this->canCustomizePageLayouts($request); if (!$canCustomizeLayout) { $this->addFlash( 'error', - $this->trans('You do not have permission to edit this.', 'Admin.Notifications.Error') + $this->trans('You do not have permission to edit this.', [], 'Admin.Notifications.Error') ); } /** @var LayoutCustomizationPage[] $pages */ - $pages = $this->getQueryBus()->handle(new GetPagesForLayoutCustomization()); + $pages = $this->dispatchQuery(new GetPagesForLayoutCustomization()); - $pageLayoutCustomizationFormFactory = - $this->get('prestashop.bundle.form.admin.improve.design.theme.page_layout_customization_form_factory'); $pageLayoutCustomizationForm = $pageLayoutCustomizationFormFactory->create($pages); $pageLayoutCustomizationForm->handleRequest($request); @@ -378,10 +390,9 @@ public function customizeLayoutsAction(Request $request) return $this->redirectToRoute('admin_theme_customize_layouts'); } - $themePageLayoutsCustomizer = $this->get('prestashop.core.addon.theme.theme.page_layouts_customizer'); $themePageLayoutsCustomizer->customize($pageLayoutCustomizationForm->getData()['layouts']); - $this->addFlash('success', $this->trans('Successful update', 'Admin.Notifications.Success')); + $this->addFlash('success', $this->trans('Successful update', [], 'Admin.Notifications.Success')); return $this->redirectToRoute('admin_themes_index'); } @@ -389,7 +400,7 @@ public function customizeLayoutsAction(Request $request) return $this->render('@PrestaShop/Admin/Improve/Design/Theme/customize_page_layouts.html.twig', [ 'pageLayoutCustomizationForm' => $pageLayoutCustomizationForm->createView(), 'pages' => $pages, - 'layoutTitle' => $this->trans('Choose layouts', 'Admin.Navigation.Menu'), + 'layoutTitle' => $this->trans('Choose layouts', [], 'Admin.Navigation.Menu'), ]); } @@ -398,22 +409,12 @@ public function customizeLayoutsAction(Request $request) * * @return bool */ - protected function canCustomizePageLayouts(Request $request) + protected function canCustomizePageLayouts(Request $request): bool { return !$this->isDemoModeEnabled() && $this->isGranted(Permission::UPDATE, $request->attributes->get('_legacy_controller')); } - /** - * @return FormInterface - * - * @throws Exception - */ - protected function getLogosUploadForm(): FormInterface - { - return $this->getShopLogosFormHandler()->getForm(); - } - /** * @return FormInterface */ @@ -422,41 +423,33 @@ protected function getAdaptThemeToRtlLanguageForm(): FormInterface return $this->createForm(AdaptThemeToRTLLanguagesType::class); } - /** - * @return FormHandlerInterface - */ - private function getShopLogosFormHandler(): FormHandlerInterface - { - return $this->get('prestashop.admin.shop_logos_settings.form_handler'); - } - /** * @param Exception $e * * @return array */ - private function handleImportThemeException(Exception $e) + private function handleImportThemeException(Exception $e): array { return [ ImportedThemeAlreadyExistsException::class => $this->trans( 'There is already a theme %theme_name% in your themes folder. Remove it if you want to continue.', - 'Admin.Design.Notification', [ '%theme_name%' => $e instanceof ImportedThemeAlreadyExistsException ? $e->getThemeName()->getValue() : '', - ] + ], + 'Admin.Design.Notification', ), ThemeConstraintException::class => [ ThemeConstraintException::RESTRICTED_ONLY_FOR_SINGLE_SHOP => $this->trans( - 'Themes can only be changed in single store context.', 'Admin.Notifications.Error' + 'Themes can only be changed in single store context.', [], 'Admin.Notifications.Error' ), ThemeConstraintException::MISSING_CONFIGURATION_FILE => $this->trans( - 'Missing configuration file', 'Admin.Notifications.Error' + 'Missing configuration file', [], 'Admin.Notifications.Error' ), ThemeConstraintException::INVALID_CONFIGURATION => $this->trans( - 'Invalid configuration', 'Admin.Notifications.Error' + 'Invalid configuration', [], 'Admin.Notifications.Error' ), ThemeConstraintException::INVALID_DATA => $this->trans( - 'Invalid data', 'Admin.Notifications.Error' + 'Invalid data', [], 'Admin.Notifications.Error' ), ], ]; @@ -467,24 +460,25 @@ private function handleImportThemeException(Exception $e) * * @return array */ - private function handleEnableThemeException(ThemeException $e) + private function handleEnableThemeException(ThemeException $e): array { return [ CannotEnableThemeException::class => $e->getMessage(), ThemeConstraintException::class => [ ThemeConstraintException::RESTRICTED_ONLY_FOR_SINGLE_SHOP => $this->trans( 'You must select a shop from the above list if you wish to choose a theme.', - 'Admin.Design.Help' + [], + 'Admin.Design.Help', ), ], FailedToEnableThemeModuleException::class => $this->trans( 'Cannot %action% module %module%. %error_details%', - 'Admin.Modules.Notification', [ - '%action%' => strtolower($this->trans('Install', 'Admin.Actions')), + '%action%' => strtolower($this->trans('Install', [], 'Admin.Actions')), '%module%' => ($e instanceof FailedToEnableThemeModuleException) ? $e->getModuleName() : '', '%error_details%' => $e->getMessage(), - ] + ], + 'Admin.Modules.Notification', ), ]; } @@ -494,22 +488,17 @@ private function handleEnableThemeException(ThemeException $e) * * @return string */ - private function handleDeleteThemeException(ThemeException $e) + private function handleDeleteThemeException(ThemeException $e): string { - $type = $e::class; - $errorMessages = [ CannotDeleteThemeException::class => $this->trans( 'Failed to delete theme. Make sure you have permissions and theme is not used.', + [], 'Admin.Design.Notification' ), ]; - if (isset($errorMessages[$type])) { - return $errorMessages[$type]; - } - - return $this->getFallbackErrorMessage($type, $e->getCode()); + return $this->getErrorMessageForException($e, $errorMessages); } /** @@ -517,19 +506,13 @@ private function handleDeleteThemeException(ThemeException $e) * * @return string */ - private function handleAdaptThemeToRTLLanguagesException(ThemeException $e) + private function handleAdaptThemeToRTLLanguagesException(ThemeException $e): string { - $type = $e::class; - $errorMessages = [ - CannotAdaptThemeToRTLLanguagesException::class => $this->trans('Cannot adapt theme to RTL languages.', 'Admin.Design.Notification'), + CannotAdaptThemeToRTLLanguagesException::class => $this->trans('Cannot adapt theme to RTL languages.', [], 'Admin.Design.Notification'), ]; - if (isset($errorMessages[$type])) { - return $errorMessages[$type]; - } - - return $this->getFallbackErrorMessage($type, $e->getCode()); + return $this->getErrorMessageForException($e, $errorMessages); } /** @@ -539,7 +522,7 @@ private function handleAdaptThemeToRTLLanguagesException(ThemeException $e) * * @return array */ - private function getLogoUploadErrorMessages(DomainException $exception) + private function getLogoUploadErrorMessages(DomainException $exception): array { $availableLogoFormatsImploded = implode(', .', ShopLogoSettings::AVAILABLE_LOGO_IMAGE_EXTENSIONS); $availableMailAndInvoiceFormatsImploded = implode(', .', ShopLogoSettings::AVAILABLE_MAIL_AND_INVOICE_LOGO_IMAGE_EXTENSIONS); @@ -547,20 +530,20 @@ private function getLogoUploadErrorMessages(DomainException $exception) $logoImageFormatError = $this->trans( 'Image format not recognized, allowed format(s) is(are): .%s', + [$availableLogoFormatsImploded], 'Admin.Notifications.Error', - [$availableLogoFormatsImploded] ); $mailAndInvoiceImageFormatError = $this->trans( 'Image format not recognized, allowed formats are: %s', + [$availableMailAndInvoiceFormatsImploded], 'Admin.Notifications.Error', - [$availableMailAndInvoiceFormatsImploded] ); $iconFormatError = $this->trans( 'Image format not recognized, allowed format(s) is(are): .%s', + [$availableIconFormat], 'Admin.Notifications.Error', - [$availableIconFormat] ); return [ @@ -570,10 +553,10 @@ private function getLogoUploadErrorMessages(DomainException $exception) FileUploadException::class => [ UPLOAD_ERR_INI_SIZE => $this->trans( 'File too large (limit of %s bytes).', - 'Admin.Notifications.Error', [ UploadedFile::getMaxFilesize(), - ] + ], + 'Admin.Notifications.Error', ), ], ]; diff --git a/src/PrestaShopBundle/Resources/config/services/adapter/language.yml b/src/PrestaShopBundle/Resources/config/services/adapter/language.yml index 515d9725c0563..e222fcf074cc8 100644 --- a/src/PrestaShopBundle/Resources/config/services/adapter/language.yml +++ b/src/PrestaShopBundle/Resources/config/services/adapter/language.yml @@ -14,11 +14,18 @@ services: - '@prestashop.core.image.parser.image_tag_source_parser' - "@=service('prestashop.adapter.legacy.context').getContext().shop.id" - prestashop.adapter.language.rtl.installed_language_checker: - class: 'PrestaShop\PrestaShop\Adapter\Language\RTL\InstalledLanguageChecker' + PrestaShop\PrestaShop\Adapter\Language\RTL\InstalledLanguageChecker: + public: false arguments: - '@prestashop.adapter.data_provider.language' + prestashop.adapter.language.rtl.installed_language_checker: + alias: 'PrestaShop\PrestaShop\Adapter\Language\RTL\InstalledLanguageChecker' + public: true + deprecated: + package: PrestaShop\PrestaShop + version: 9.0 + prestashop.adapter.language.command_handler.add_language_handler: class: 'PrestaShop\PrestaShop\Adapter\Language\CommandHandler\AddLanguageHandler' autoconfigure: true diff --git a/src/PrestaShopBundle/Resources/config/services/core/addon.yml b/src/PrestaShopBundle/Resources/config/services/core/addon.yml index 7fe095f58fbb2..f0103d22d0ff4 100644 --- a/src/PrestaShopBundle/Resources/config/services/core/addon.yml +++ b/src/PrestaShopBundle/Resources/config/services/core/addon.yml @@ -9,14 +9,20 @@ services: - "@filesystem" - "@=service('prestashop.adapter.legacy.context').getContext().shop" - prestashop.core.addon.theme.exporter: - class: PrestaShop\PrestaShop\Core\Addon\Theme\ThemeExporter + PrestaShop\PrestaShop\Core\Addon\Theme\ThemeExporter: + public: false arguments: - "@prestashop.adapter.legacy.configuration" - "@filesystem" - "@prestashop.core.admin.lang.repository" - "@prestashop.translation.theme.exporter" + prestashop.core.addon.theme.exporter: + alias: PrestaShop\PrestaShop\Core\Addon\Theme\ThemeExporter + public: true + deprecated: + package: PrestaShop\PrestaShop + version: 9.0 prestashop.core.addon.theme.theme_validator: class: PrestaShop\PrestaShop\Core\Addon\Theme\ThemeValidator @@ -38,21 +44,35 @@ services: lazy: true factory: [ '@prestashop.core.addon.theme.theme_manager_builder', 'build' ] - prestashop.core.addon.theme.theme.page_layouts_customizer: - class: PrestaShop\PrestaShop\Core\Addon\Theme\ThemePageLayoutsCustomizer + PrestaShop\PrestaShop\Core\Addon\Theme\ThemePageLayoutsCustomizer: + public: false lazy: true arguments: - '@=service("prestashop.adapter.legacy.context").getContext().shop.theme' - '@prestashop.core.addon.theme.theme_manager' - '@prestashop.adapter.cache.clearer.smarty_cache_clearer' + prestashop.core.addon.theme.theme.page_layouts_customizer: + alias: PrestaShop\PrestaShop\Core\Addon\Theme\ThemePageLayoutsCustomizer + public: true + deprecated: + package: PrestaShop\PrestaShop + version: 9.0 + prestashop.core.addon.theme.theme_zip_uploader: class: PrestaShop\PrestaShop\Core\Addon\Theme\ThemeZipUploader arguments: - '@prestashop.adapter.legacy.configuration' - prestashop.core.addon.theme.theme_provider: - class: PrestaShop\PrestaShop\Core\Addon\Theme\ThemeProvider + PrestaShop\PrestaShop\Core\Addon\Theme\ThemeProvider: + public: false arguments: - '@prestashop.core.addon.theme.repository' - '@=service("prestashop.adapter.legacy.context").getContext().shop.theme' + + prestashop.core.addon.theme.theme_provider: + alias: PrestaShop\PrestaShop\Core\Addon\Theme\ThemeProvider + public: true + deprecated: + package: PrestaShop\PrestaShop + version: 9.0 From 4fed7fbb2aa844924d7247ee521309383db3e988 Mon Sep 17 00:00:00 2001 From: Jonathan LELIEVRE Date: Tue, 29 Oct 2024 10:31:57 +0100 Subject: [PATCH 4/6] Refacto CustomerController based on PrestaShopAdminController --- .../CustomerDiscountGridDataFactory.php | 19 +- .../Sell/Customer/CustomerController.php | 308 ++++++++++-------- .../Resources/config/services/core/b2b.yml | 11 +- .../services/core/grid/grid_data_factory.yml | 2 - 4 files changed, 186 insertions(+), 154 deletions(-) diff --git a/src/Core/Grid/Data/Factory/CustomerDiscountGridDataFactory.php b/src/Core/Grid/Data/Factory/CustomerDiscountGridDataFactory.php index 05c28f11234bf..0541d9831094c 100644 --- a/src/Core/Grid/Data/Factory/CustomerDiscountGridDataFactory.php +++ b/src/Core/Grid/Data/Factory/CustomerDiscountGridDataFactory.php @@ -29,36 +29,23 @@ namespace PrestaShop\PrestaShop\Core\Grid\Data\Factory; use CartRule; -use Customer; use PrestaShop\PrestaShop\Core\Grid\Data\GridData; use PrestaShop\PrestaShop\Core\Grid\Record\RecordCollection; use PrestaShop\PrestaShop\Core\Grid\Search\SearchCriteriaInterface; /** - * Class CustomerDiscountGridDataFactory is responsible of returning grid data for customer's discounts. + * Class CustomerDiscountGridDataFactory is responsible for returning grid data for customer's discounts. */ final class CustomerDiscountGridDataFactory implements GridDataFactoryInterface { - /** - * @var Customer - */ - private $customer; - - /** - * @param Customer $customer - */ - public function __construct(Customer $customer) - { - $this->customer = $customer; - } - /** * {@inheritdoc} */ public function getData(SearchCriteriaInterface $searchCriteria) { + $customerFilters = $searchCriteria->getFilters(); $allDiscounts = CartRule::getAllCustomerCartRules( - $this->customer->id + $customerFilters['id_customer'] ); $discountsToDisplay = array_slice( diff --git a/src/PrestaShopBundle/Controller/Admin/Sell/Customer/CustomerController.php b/src/PrestaShopBundle/Controller/Admin/Sell/Customer/CustomerController.php index 4ff1f20975d40..47b43fac0a6f4 100644 --- a/src/PrestaShopBundle/Controller/Admin/Sell/Customer/CustomerController.php +++ b/src/PrestaShopBundle/Controller/Admin/Sell/Customer/CustomerController.php @@ -27,6 +27,8 @@ namespace PrestaShopBundle\Controller\Admin\Sell\Customer; use Exception; +use PrestaShop\PrestaShop\Adapter\LegacyContext; +use PrestaShop\PrestaShop\Core\B2b\B2bFeature; use PrestaShop\PrestaShop\Core\Domain\Customer\Command\BulkDeleteCustomerCommand; use PrestaShop\PrestaShop\Core\Domain\Customer\Command\BulkDisableCustomerCommand; use PrestaShop\PrestaShop\Core\Domain\Customer\Command\BulkEnableCustomerCommand; @@ -57,6 +59,11 @@ use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopConstraint; use PrestaShop\PrestaShop\Core\Domain\ShowcaseCard\Query\GetShowcaseCardIsClosed; use PrestaShop\PrestaShop\Core\Domain\ShowcaseCard\ValueObject\ShowcaseCard; +use PrestaShop\PrestaShop\Core\Form\IdentifiableObject\Builder\FormBuilderInterface; +use PrestaShop\PrestaShop\Core\Form\IdentifiableObject\Handler\FormHandlerInterface; +use PrestaShop\PrestaShop\Core\Grid\GridFactoryInterface; +use PrestaShop\PrestaShop\Core\Group\Provider\DefaultGroupsProviderInterface; +use PrestaShop\PrestaShop\Core\Kpi\Row\KpiRowFactoryInterface; use PrestaShop\PrestaShop\Core\Search\Filters\CustomerAddressFilters; use PrestaShop\PrestaShop\Core\Search\Filters\CustomerBoughtProductFilters; use PrestaShop\PrestaShop\Core\Search\Filters\CustomerCartFilters; @@ -65,13 +72,14 @@ use PrestaShop\PrestaShop\Core\Search\Filters\CustomerOrderFilters; use PrestaShop\PrestaShop\Core\Search\Filters\CustomerViewedProductFilters; use PrestaShopBundle\Component\CsvResponse; -use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController as AbstractAdminController; +use PrestaShopBundle\Controller\Admin\PrestaShopAdminController; use PrestaShopBundle\Form\Admin\Sell\Customer\DeleteCustomersType; use PrestaShopBundle\Form\Admin\Sell\Customer\PrivateNoteType; use PrestaShopBundle\Form\Admin\Sell\Customer\RequiredFieldsType; use PrestaShopBundle\Form\Admin\Sell\Customer\TransferGuestAccountType; use PrestaShopBundle\Security\Attribute\AdminSecurity; use PrestaShopBundle\Security\Attribute\DemoRestricted; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -81,7 +89,7 @@ /** * Class CustomerController manages "Sell > Customers" page. */ -class CustomerController extends AbstractAdminController +class CustomerController extends PrestaShopAdminController { /** * Show customers listing. @@ -92,17 +100,20 @@ class CustomerController extends AbstractAdminController * @return Response */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller'))", redirectRoute: 'admin_customers_index', message: 'You do not have permission to view this.')] - public function indexAction(Request $request, CustomerFilters $filters) - { - $customersKpiFactory = $this->get('prestashop.core.kpi_row.factory.customers'); - - $customerGridFactory = $this->get('prestashop.core.grid.factory.customer'); + public function indexAction( + Request $request, + CustomerFilters $filters, + #[Autowire(service: 'prestashop.core.kpi_row.factory.customers')] + KpiRowFactoryInterface $customersKpiFactory, + #[Autowire(service: 'prestashop.core.grid.factory.customer')] + GridFactoryInterface $customerGridFactory, + ): Response { $customerGrid = $customerGridFactory->getGrid($filters); $deleteCustomerForm = $this->createForm(DeleteCustomersType::class); - $showcaseCardIsClosed = $this->getQueryBus()->handle( - new GetShowcaseCardIsClosed((int) $this->getContext()->employee->id, ShowcaseCard::CUSTOMERS_CARD) + $showcaseCardIsClosed = $this->dispatchQuery( + new GetShowcaseCardIsClosed($this->getEmployeeContext()->getEmployee()->getId(), ShowcaseCard::CUSTOMERS_CARD) ); return $this->render('@PrestaShop/Admin/Sell/Customer/index.html.twig', [ @@ -110,7 +121,7 @@ public function indexAction(Request $request, CustomerFilters $filters) 'customerGrid' => $this->presentGrid($customerGrid), 'customersKpi' => $customersKpiFactory->build(), 'customerRequiredFieldsForm' => $this->getRequiredFieldsForm()->createView(), - 'isSingleShopContext' => $this->get('prestashop.adapter.shop.context')->isSingleShopContext(), + 'isSingleShopContext' => $this->getShopContext()->getShopConstraint()->isSingleShopContext(), 'deleteCustomersForm' => $deleteCustomerForm->createView(), 'showcaseCardName' => ShowcaseCard::CUSTOMERS_CARD, 'isShowcaseCardClosed' => $showcaseCardIsClosed, @@ -127,32 +138,38 @@ public function indexAction(Request $request, CustomerFilters $filters) * @return Response */ #[AdminSecurity("is_granted('create', request.get('_legacy_controller'))")] - public function createAction(Request $request) - { - if (!$this->get('prestashop.adapter.shop.context')->isSingleShopContext()) { + public function createAction( + Request $request, + #[Autowire(service: 'prestashop.core.form.identifiable_object.builder.customer_form_builder')] + FormBuilderInterface $formBuilder, + #[Autowire(service: 'prestashop.core.form.identifiable_object.handler.customer_form_handler')] + FormHandlerInterface $formHandler, + #[Autowire(service: 'prestashop.adapter.group.provider.default_groups_provider')] + DefaultGroupsProviderInterface $defaultGroupsProvider, + B2bFeature $b2bFeature, + ): Response { + if (!$this->getShopContext()->getShopConstraint()->isSingleShopContext()) { return $this->redirectToRoute('admin_customers_index'); } $this->addGroupSelectionToRequest($request); - $customerForm = $this->get('prestashop.core.form.identifiable_object.builder.customer_form_builder')->getForm( + $customerForm = $formBuilder->getForm( [], [ - 'show_guest_field' => (bool) $this->get('prestashop.adapter.legacy.configuration')->get('PS_GUEST_CHECKOUT_ENABLED'), + 'show_guest_field' => (bool) $this->getConfiguration()->get('PS_GUEST_CHECKOUT_ENABLED'), ] ); $customerForm->handleRequest($request); - $customerFormHandler = $this->get('prestashop.core.form.identifiable_object.handler.customer_form_handler'); - try { - $result = $customerFormHandler->handle($customerForm); + $result = $formHandler->handle($customerForm); if ($customerId = $result->getIdentifiableObjectId()) { - $this->addFlash('success', $this->trans('Successful creation', 'Admin.Notifications.Success')); + $this->addFlash('success', $this->trans('Successful creation', [], 'Admin.Notifications.Success')); if ($request->query->has('submitFormAjax')) { /** @var ViewableCustomer $customerInformation */ - $customerInformation = $this->getQueryBus()->handle(new GetCustomerForViewing((int) $customerId)); + $customerInformation = $this->dispatchQuery(new GetCustomerForViewing((int) $customerId)); return $this->render('@PrestaShop/Admin/Sell/Customer/modal_create_success.html.twig', [ 'customerId' => $customerId, @@ -167,16 +184,16 @@ public function createAction(Request $request) } // Get default groups for JS purposes - $defaultGroups = $this->get('prestashop.adapter.group.provider.default_groups_provider')->getGroups(); + $defaultGroups = $defaultGroupsProvider->getGroups(); return $this->render('@PrestaShop/Admin/Sell/Customer/create.html.twig', [ 'customerForm' => $customerForm->createView(), - 'isB2bFeatureActive' => $this->get('prestashop.core.b2b.b2b_feature')->isActive(), + 'isB2bFeatureActive' => $b2bFeature->isActive(), 'minPasswordLength' => Password::MIN_LENGTH, 'displayInIframe' => $request->query->has('submitFormAjax'), 'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')), 'enableSidebar' => true, - 'layoutTitle' => $this->trans('New customer', 'Admin.Navigation.Menu'), + 'layoutTitle' => $this->trans('New customer', [], 'Admin.Navigation.Menu'), 'defaultGroups' => [ $defaultGroups->getVisitorsGroup()->getId(), $defaultGroups->getGuestsGroup()->getId(), @@ -196,18 +213,25 @@ public function createAction(Request $request) * @return Response */ #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))")] - public function editAction($customerId, Request $request) - { + public function editAction( + int $customerId, + Request $request, + #[Autowire(service: 'prestashop.core.form.identifiable_object.builder.customer_form_builder')] + FormBuilderInterface $formBuilder, + #[Autowire(service: 'prestashop.core.form.identifiable_object.handler.customer_form_handler')] + FormHandlerInterface $formHandler, + B2bFeature $b2bFeature, + ): Response { $this->addGroupSelectionToRequest($request); /** @var EditableCustomer $customerInformation */ - $customerInformation = $this->getQueryBus()->handle(new GetCustomerForEditing((int) $customerId)); + $customerInformation = $this->dispatchQuery(new GetCustomerForEditing($customerId)); $customerFormOptions = [ 'is_password_required' => false, 'show_guest_field' => false, ]; + try { - $customerForm = $this->get('prestashop.core.form.identifiable_object.builder.customer_form_builder') - ->getFormFor((int) $customerId, [], $customerFormOptions); + $customerForm = $formBuilder->getFormFor((int) $customerId, [], $customerFormOptions); } catch (Exception $exception) { $this->addFlash( 'error', @@ -219,10 +243,9 @@ public function editAction($customerId, Request $request) try { $customerForm->handleRequest($request); - $customerFormHandler = $this->get('prestashop.core.form.identifiable_object.handler.customer_form_handler'); - $result = $customerFormHandler->handleFor((int) $customerId, $customerForm); + $result = $formHandler->handleFor((int) $customerId, $customerForm); if ($result->isSubmitted() && $result->isValid()) { - $this->addFlash('success', $this->trans('Successful update', 'Admin.Notifications.Success')); + $this->addFlash('success', $this->trans('Successful update', [], 'Admin.Notifications.Success')); return $this->redirectToRoute('admin_customers_index'); } @@ -236,16 +259,16 @@ public function editAction($customerId, Request $request) return $this->render('@PrestaShop/Admin/Sell/Customer/edit.html.twig', [ 'customerForm' => $customerForm->createView(), 'customerInformation' => $customerInformation, - 'isB2bFeatureActive' => $this->get('prestashop.core.b2b.b2b_feature')->isActive(), + 'isB2bFeatureActive' => $b2bFeature->isActive(), 'minPasswordLength' => Password::MIN_LENGTH, 'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')), 'enableSidebar' => true, 'layoutTitle' => $this->trans( 'Editing customer %name%', - 'Admin.Navigation.Menu', [ '%name%' => mb_substr($customerInformation->getFirstName()->getValue(), 0, 1) . '. ' . $customerInformation->getLastName()->getValue(), - ] + ], + 'Admin.Navigation.Menu', ), ]); } @@ -267,22 +290,34 @@ public function editAction($customerId, Request $request) #[DemoRestricted(redirectRoute: 'admin_customers_index')] #[AdminSecurity("is_granted('read', request.get('_legacy_controller'))", redirectRoute: 'admin_customers_index')] public function viewAction( - $customerId, + int $customerId, Request $request, CustomerDiscountFilters $customerDiscountFilters, CustomerAddressFilters $customerAddressFilters, CustomerCartFilters $customerCartFilters, CustomerOrderFilters $customerOrderFilters, CustomerBoughtProductFilters $customerBoughtProductFilters, - CustomerViewedProductFilters $customerViewedProductFilters - ) { + CustomerViewedProductFilters $customerViewedProductFilters, + #[Autowire(service: 'prestashop.core.grid.factory.customer.discount')] + GridFactoryInterface $customerDiscountGridFactory, + #[Autowire(service: 'prestashop.core.grid.factory.customer.address')] + GridFactoryInterface $customerAddressGridFactory, + #[Autowire(service: 'prestashop.core.grid.factory.customer.order')] + GridFactoryInterface $customerOrderGridFactory, + #[Autowire(service: 'prestashop.core.grid.factory.customer.cart')] + GridFactoryInterface $customerCartGridFactory, + #[Autowire(service: 'prestashop.core.grid.factory.customer.bought_product')] + GridFactoryInterface $customerBoughtProductGridFactory, + #[Autowire(service: 'prestashop.core.grid.factory.customer.viewed_product')] + GridFactoryInterface $customerViewedProductGridFactory, + ): Response { try { /** @var ViewableCustomer $customerInformation */ - $customerInformation = $this->getQueryBus()->handle(new GetCustomerForViewing((int) $customerId)); + $customerInformation = $this->dispatchQuery(new GetCustomerForViewing($customerId)); } catch (CustomerNotFoundException $e) { $this->addFlash( 'error', - $this->trans('This customer does not exist.', 'Admin.Orderscustomers.Notification') + $this->trans('This customer does not exist.', [], 'Admin.Orderscustomers.Notification') ); return $this->redirectToRoute('admin_customers_index'); @@ -300,32 +335,26 @@ public function viewAction( ]); // Discount listing - $customerDiscountGridFactory = $this->get('prestashop.core.grid.factory.customer.discount'); $customerDiscountFilters->addFilter(['id_customer' => $customerId]); $customerDiscountGrid = $customerDiscountGridFactory->getGrid($customerDiscountFilters); // Addresses listing - $customerAddressGridFactory = $this->get('prestashop.core.grid.factory.customer.address'); $customerAddressFilters->addFilter(['id_customer' => $customerId]); $customerAddressGrid = $customerAddressGridFactory->getGrid($customerAddressFilters); // Order listing - $customerOrderGridFactory = $this->get('prestashop.core.grid.factory.customer.order'); $customerOrderFilters->addFilter(['id_customer' => $customerId]); $customerOrderGrid = $customerOrderGridFactory->getGrid($customerOrderFilters); // Cart listing - $customerCartGridFactory = $this->get('prestashop.core.grid.factory.customer.cart'); $customerCartFilters->addFilter(['id_customer' => $customerId]); $customerCartGrid = $customerCartGridFactory->getGrid($customerCartFilters); // Bought products listing - $customerBoughtProductGridFactory = $this->get('prestashop.core.grid.factory.customer.bought_product'); $customerBoughtProductFilters->addFilter(['id_customer' => $customerId]); $customerBoughtProductGrid = $customerBoughtProductGridFactory->getGrid($customerBoughtProductFilters); // Viewed products listing - $customerViewedProductGridFactory = $this->get('prestashop.core.grid.factory.customer.viewed_product'); $customerViewedProductFilters->addFilter(['id_customer' => $customerId]); $customerViewedProductGrid = $customerViewedProductGridFactory->getGrid($customerViewedProductFilters); @@ -343,16 +372,16 @@ public function viewAction( 'customerCartGrid' => $this->presentGrid($customerCartGrid), 'customerBoughtProductGrid' => $this->presentGrid($customerBoughtProductGrid), 'customerViewedProductGrid' => $this->presentGrid($customerViewedProductGrid), - 'isMultistoreEnabled' => $this->get('prestashop.adapter.feature.multistore')->isActive(), + 'isMultistoreEnabled' => $this->getShopContext()->isMultiShopEnabled(), 'transferGuestAccountForm' => $transferGuestAccountForm, 'privateNoteForm' => $privateNoteForm->createView(), 'layoutHeaderToolbarBtn' => $this->getCustomerViewToolbarButtons($customerId), 'layoutTitle' => $this->trans( 'Customer %name%', - 'Admin.Navigation.Menu', [ '%name%' => mb_substr($customerInformation->getPersonalInformation()->getFirstName(), 0, 1) . '. ' . $customerInformation->getPersonalInformation()->getLastName(), - ] + ], + 'Admin.Navigation.Menu', ), ]); } @@ -363,10 +392,10 @@ public function viewAction( * @param int $customerId * @param Request $request * - * @return Response + * @return RedirectResponse */ #[AdminSecurity("is_granted('update', request.get('_legacy_controller')) && is_granted('create', request.get('_legacy_controller'))", redirectRoute: 'admin_customers_index')] - public function setPrivateNoteAction($customerId, Request $request) + public function setPrivateNoteAction(int $customerId, Request $request): RedirectResponse { $privateNoteForm = $this->createForm(PrivateNoteType::class); $privateNoteForm->handleRequest($request); @@ -375,11 +404,11 @@ public function setPrivateNoteAction($customerId, Request $request) $data = $privateNoteForm->getData(); try { - $this->getCommandBus()->handle(new SetPrivateNoteAboutCustomerCommand( - (int) $customerId, + $this->dispatchCommand(new SetPrivateNoteAboutCustomerCommand( + $customerId, $data['note'] )); - $this->addFlash('success', $this->trans('Successful update', 'Admin.Notifications.Success')); + $this->addFlash('success', $this->trans('Successful update', [], 'Admin.Notifications.Success')); } catch (CustomerException $e) { $this->addFlash( 'error', @@ -402,18 +431,21 @@ public function setPrivateNoteAction($customerId, Request $request) * @return RedirectResponse */ #[AdminSecurity("is_granted('update', request.get('_legacy_controller')) && is_granted('create', request.get('_legacy_controller'))", redirectRoute: 'admin_customers_index')] - public function transformGuestToCustomerAction($customerId, Request $request) - { + public function transformGuestToCustomerAction( + int $customerId, + Request $request, + LegacyContext $legacyContext, + ): RedirectResponse { try { - $this->getCommandBus()->handle(new TransformGuestToCustomerCommand((int) $customerId)); + $this->dispatchCommand(new TransformGuestToCustomerCommand($customerId)); - $this->addFlash('success', $this->trans('Successful creation', 'Admin.Notifications.Success')); + $this->addFlash('success', $this->trans('Successful creation', [], 'Admin.Notifications.Success')); } catch (CustomerException $e) { $this->addFlash('error', $this->getErrorMessageForException($e, $this->getErrorMessages($e))); } if ($request->query->get('id_order')) { - $legacyLink = $this->getAdminLink('AdminOrders', [ + $legacyLink = $legacyContext->getAdminLink('AdminOrders', true, [ 'id_order' => $request->query->get('id_order'), 'vieworder' => true, ]); @@ -434,7 +466,7 @@ public function transformGuestToCustomerAction($customerId, Request $request) * @return RedirectResponse */ #[AdminSecurity("is_granted('update', request.get('_legacy_controller')) && is_granted('create', request.get('_legacy_controller'))", redirectRoute: 'admin_customers_index')] - public function setRequiredFieldsAction(Request $request) + public function setRequiredFieldsAction(Request $request): RedirectResponse { $requiredFieldsForm = $this->getRequiredFieldsForm(); $requiredFieldsForm->handleRequest($request); @@ -442,9 +474,9 @@ public function setRequiredFieldsAction(Request $request) if ($requiredFieldsForm->isSubmitted()) { $data = $requiredFieldsForm->getData(); - $this->getCommandBus()->handle(new SetRequiredFieldsForCustomerCommand($data['required_fields'])); + $this->dispatchCommand(new SetRequiredFieldsForCustomerCommand($data['required_fields'])); - $this->addFlash('success', $this->trans('Successful update', 'Admin.Notifications.Success')); + $this->addFlash('success', $this->trans('Successful update', [], 'Admin.Notifications.Success')); } return $this->redirectToRoute('admin_customers_index'); @@ -458,7 +490,7 @@ public function setRequiredFieldsAction(Request $request) * @return JsonResponse */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller')) || is_granted('create', 'AdminOrders')")] - public function searchAction(Request $request) + public function searchAction(Request $request): JsonResponse { $query = $request->query->get('customer_search'); $phrases = explode(' OR ', $query); @@ -473,7 +505,7 @@ public function searchAction(Request $request) } try { - $customers = $this->getQueryBus()->handle(new SearchCustomers( + $customers = $this->dispatchQuery(new SearchCustomers( $phrases, $shopConstraint )); @@ -504,13 +536,13 @@ public function searchAction(Request $request) * @return JsonResponse */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller'))")] - public function getCustomerInformationAction(Request $request): Response + public function getCustomerInformationAction(Request $request): JsonResponse { try { $email = $request->query->get('email'); /** @var AddressCreationCustomerInformation $customerInformation */ - $customerInformation = $this->getQueryBus()->handle(new GetCustomerForAddressCreation($email)); + $customerInformation = $this->dispatchQuery(new GetCustomerForAddressCreation($email)); return $this->json($customerInformation); } catch (Exception $e) { @@ -536,20 +568,20 @@ public function getCustomerInformationAction(Request $request): Response * @return JsonResponse */ #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_customers_index', message: 'You do not have permission to edit this.')] - public function toggleStatusAction($customerId) + public function toggleStatusAction(int $customerId): JsonResponse { try { /** @var EditableCustomer $editableCustomer */ - $editableCustomer = $this->getQueryBus()->handle(new GetCustomerForEditing((int) $customerId)); + $editableCustomer = $this->dispatchQuery(new GetCustomerForEditing($customerId)); $editCustomerCommand = new EditCustomerCommand((int) $customerId); $editCustomerCommand->setIsEnabled(!$editableCustomer->isEnabled()); - $this->getCommandBus()->handle($editCustomerCommand); + $this->dispatchCommand($editCustomerCommand); $response = [ 'status' => true, - 'message' => $this->trans('The status has been successfully updated.', 'Admin.Notifications.Success'), + 'message' => $this->trans('The status has been successfully updated.', [], 'Admin.Notifications.Success'), ]; } catch (CustomerException $e) { $response = [ @@ -569,22 +601,22 @@ public function toggleStatusAction($customerId) * @return JsonResponse */ #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_customers_index', message: 'You do not have permission to edit this.')] - public function toggleNewsletterSubscriptionAction($customerId) + public function toggleNewsletterSubscriptionAction(int $customerId): JsonResponse { try { /** @var EditableCustomer $editableCustomer */ - $editableCustomer = $this->getQueryBus()->handle(new GetCustomerForEditing((int) $customerId)); + $editableCustomer = $this->dispatchQuery(new GetCustomerForEditing($customerId)); - $editCustomerCommand = new EditCustomerCommand((int) $customerId); + $editCustomerCommand = new EditCustomerCommand($customerId); // toggle newsletter subscription $editCustomerCommand->setNewsletterSubscribed(!$editableCustomer->isNewsletterSubscribed()); - $this->getCommandBus()->handle($editCustomerCommand); + $this->dispatchCommand($editCustomerCommand); $response = [ 'status' => true, - 'message' => $this->trans('The status has been successfully updated.', 'Admin.Notifications.Success'), + 'message' => $this->trans('The status has been successfully updated.', [], 'Admin.Notifications.Success'), ]; } catch (CustomerException $e) { $response = [ @@ -604,20 +636,20 @@ public function toggleNewsletterSubscriptionAction($customerId) * @return JsonResponse */ #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_customers_index', message: 'You do not have permission to edit this.')] - public function togglePartnerOfferSubscriptionAction($customerId) + public function togglePartnerOfferSubscriptionAction(int $customerId): JsonResponse { try { /** @var EditableCustomer $editableCustomer */ - $editableCustomer = $this->getQueryBus()->handle(new GetCustomerForEditing((int) $customerId)); + $editableCustomer = $this->dispatchQuery(new GetCustomerForEditing($customerId)); - $editCustomerCommand = new EditCustomerCommand((int) $customerId); + $editCustomerCommand = new EditCustomerCommand($customerId); $editCustomerCommand->setIsPartnerOffersSubscribed(!$editableCustomer->isPartnerOffersSubscribed()); - $this->getCommandBus()->handle($editCustomerCommand); + $this->dispatchCommand($editCustomerCommand); $response = [ 'status' => true, - 'message' => $this->trans('The status has been successfully updated.', 'Admin.Notifications.Success'), + 'message' => $this->trans('The status has been successfully updated.', [], 'Admin.Notifications.Success'), ]; } catch (CustomerException $e) { $response = [ @@ -637,7 +669,7 @@ public function togglePartnerOfferSubscriptionAction($customerId) * @return RedirectResponse */ #[AdminSecurity("is_granted('delete', request.get('_legacy_controller'))", redirectRoute: 'admin_customers_index', message: 'You do not have permission to delete this.')] - public function deleteBulkAction(Request $request) + public function deleteBulkAction(Request $request): RedirectResponse { $form = $this->createForm(DeleteCustomersType::class); $form->handleRequest($request); @@ -655,11 +687,11 @@ public function deleteBulkAction(Request $request) $data['delete_method'] ); - $this->getCommandBus()->handle($command); + $this->dispatchCommand($command); $this->addFlash( 'success', - $this->trans('The selection has been successfully deleted.', 'Admin.Notifications.Success') + $this->trans('The selection has been successfully deleted.', [], 'Admin.Notifications.Success') ); } catch (CustomerException $e) { $this->addFlash('error', $this->getErrorMessageForException($e, $this->getErrorMessages($e))); @@ -677,7 +709,7 @@ public function deleteBulkAction(Request $request) * @return RedirectResponse */ #[AdminSecurity("is_granted('delete', request.get('_legacy_controller'))", redirectRoute: 'admin_customers_index', message: 'You do not have permission to delete this.')] - public function deleteAction(Request $request) + public function deleteAction(Request $request): RedirectResponse { $form = $this->createForm(DeleteCustomersType::class); $form->handleRequest($request); @@ -693,9 +725,9 @@ public function deleteAction(Request $request) $data['delete_method'] ); - $this->getCommandBus()->handle($command); + $this->dispatchCommand($command); - $this->addFlash('success', $this->trans('Successful deletion', 'Admin.Notifications.Success')); + $this->addFlash('success', $this->trans('Successful deletion', [], 'Admin.Notifications.Success')); } catch (CustomerException $e) { $this->addFlash('error', $this->getErrorMessageForException($e, $this->getErrorMessages($e))); } @@ -712,7 +744,7 @@ public function deleteAction(Request $request) * @return RedirectResponse */ #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_customers_index', message: 'You do not have permission to edit this.')] - public function enableBulkAction(Request $request) + public function enableBulkAction(Request $request): RedirectResponse { $customerIds = array_map(function ($customerId) { return (int) $customerId; @@ -721,9 +753,9 @@ public function enableBulkAction(Request $request) try { $command = new BulkEnableCustomerCommand($customerIds); - $this->getCommandBus()->handle($command); + $this->dispatchCommand($command); - $this->addFlash('success', $this->trans('Successful update', 'Admin.Notifications.Success')); + $this->addFlash('success', $this->trans('Successful update', [], 'Admin.Notifications.Success')); } catch (CustomerException $e) { $this->addFlash('error', $this->getErrorMessageForException($e, $this->getErrorMessages($e))); } @@ -739,7 +771,7 @@ public function enableBulkAction(Request $request) * @return RedirectResponse */ #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_customers_index', message: 'You do not have permission to edit this.')] - public function disableBulkAction(Request $request) + public function disableBulkAction(Request $request): RedirectResponse { try { $customerIds = array_map(function ($customerId) { @@ -748,9 +780,9 @@ public function disableBulkAction(Request $request) $command = new BulkDisableCustomerCommand($customerIds); - $this->getCommandBus()->handle($command); + $this->dispatchCommand($command); - $this->addFlash('success', $this->trans('Successful update', 'Admin.Notifications.Success')); + $this->addFlash('success', $this->trans('Successful update', [], 'Admin.Notifications.Success')); } catch (CustomerException $e) { $this->addFlash('error', $this->getErrorMessageForException($e, $this->getErrorMessages($e))); } @@ -766,26 +798,28 @@ public function disableBulkAction(Request $request) * @return CsvResponse */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller'))")] - public function exportAction(CustomerFilters $filters) - { + public function exportAction( + CustomerFilters $filters, + #[Autowire(service: 'prestashop.core.grid.factory.customer')] + GridFactoryInterface $customerGridFactory, + ): CsvResponse { $filters = new CustomerFilters(['limit' => null] + $filters->all()); - $gridFactory = $this->get('prestashop.core.grid.factory.customer'); - $grid = $gridFactory->getGrid($filters); + $grid = $customerGridFactory->getGrid($filters); $headers = [ - 'id_customer' => $this->trans('ID', 'Admin.Global'), - 'social_title' => $this->trans('Social title', 'Admin.Global'), - 'firstname' => $this->trans('First name', 'Admin.Global'), - 'lastname' => $this->trans('Last name', 'Admin.Global'), - 'email' => $this->trans('Email address', 'Admin.Global'), - 'default_group' => $this->trans('Group', 'Admin.Global'), - 'company' => $this->trans('Company', 'Admin.Global'), - 'total_spent' => $this->trans('Sales', 'Admin.Global'), - 'enabled' => $this->trans('Enabled', 'Admin.Global'), - 'newsletter' => $this->trans('Newsletter', 'Admin.Global'), - 'partner_offers' => $this->trans('Partner offers', 'Admin.Orderscustomers.Feature'), - 'registration' => $this->trans('Registration', 'Admin.Orderscustomers.Feature'), - 'connect' => $this->trans('Last visit', 'Admin.Orderscustomers.Feature'), + 'id_customer' => $this->trans('ID', [], 'Admin.Global'), + 'social_title' => $this->trans('Social title', [], 'Admin.Global'), + 'firstname' => $this->trans('First name', [], 'Admin.Global'), + 'lastname' => $this->trans('Last name', [], 'Admin.Global'), + 'email' => $this->trans('Email address', [], 'Admin.Global'), + 'default_group' => $this->trans('Group', [], 'Admin.Global'), + 'company' => $this->trans('Company', [], 'Admin.Global'), + 'total_spent' => $this->trans('Sales', [], 'Admin.Global'), + 'enabled' => $this->trans('Enabled', [], 'Admin.Global'), + 'newsletter' => $this->trans('Newsletter', [], 'Admin.Global'), + 'partner_offers' => $this->trans('Partner offers', [], 'Admin.Orderscustomers.Feature'), + 'registration' => $this->trans('Registration', [], 'Admin.Orderscustomers.Feature'), + 'connect' => $this->trans('Last visit', [], 'Admin.Orderscustomers.Feature'), ]; $data = []; @@ -820,10 +854,10 @@ public function exportAction(CustomerFilters $filters) * @return JsonResponse */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller')) || is_granted('create', 'AdminOrders')")] - public function getCartsAction(int $customerId) + public function getCartsAction(int $customerId): JsonResponse { try { - $carts = $this->getQueryBus()->handle(new GetCustomerCarts($customerId)); + $carts = $this->dispatchQuery(new GetCustomerCarts($customerId)); } catch (Exception $e) { return $this->json( ['message' => $this->getErrorMessageForException($e, $this->getErrorMessages($e))], @@ -842,10 +876,10 @@ public function getCartsAction(int $customerId) * @return JsonResponse */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller')) || is_granted('create', 'AdminOrders')")] - public function getOrdersAction(int $customerId) + public function getOrdersAction(int $customerId): JsonResponse { try { - $orders = $this->getQueryBus()->handle(new GetCustomerOrders($customerId)); + $orders = $this->dispatchQuery(new GetCustomerOrders($customerId)); } catch (Exception $e) { return $this->json( ['message' => $this->getErrorMessageForException($e, $this->getErrorMessages($e))], @@ -861,9 +895,9 @@ public function getOrdersAction(int $customerId) /** * @return FormInterface */ - private function getRequiredFieldsForm() + private function getRequiredFieldsForm(): FormInterface { - $requiredFields = $this->getQueryBus()->handle(new GetRequiredFieldsForCustomer()); + $requiredFields = $this->dispatchQuery(new GetRequiredFieldsForCustomer()); return $this->createForm(RequiredFieldsType::class, ['required_fields' => $requiredFields]); } @@ -874,7 +908,7 @@ private function getRequiredFieldsForm() * * @param Request $request */ - private function addGroupSelectionToRequest(Request $request) + private function addGroupSelectionToRequest(Request $request): void { if (!$request->isMethod(Request::METHOD_POST)) { return; @@ -899,84 +933,89 @@ private function addGroupSelectionToRequest(Request $request) * * @return array */ - private function getErrorMessages(Exception $e) + private function getErrorMessages(Exception $e): array { return [ CustomerNotFoundException::class => $this->trans( 'This customer does not exist.', + [], 'Admin.Orderscustomers.Notification' ), DuplicateCustomerEmailException::class => [ DuplicateCustomerEmailException::ADD => $this->trans( 'You can\'t create a registered customer with email "%s", because a registered customer with this email already exists.', + [$e instanceof DuplicateCustomerEmailException ? $e->getEmail()->getValue() : ''], 'Admin.Orderscustomers.Notification', - [$e instanceof DuplicateCustomerEmailException ? $e->getEmail()->getValue() : ''] ), DuplicateCustomerEmailException::EDIT => $this->trans( 'You can\'t update the email to "%s", because a registered customer with this email already exists.', + [$e instanceof DuplicateCustomerEmailException ? $e->getEmail()->getValue() : ''], 'Admin.Orderscustomers.Notification', - [$e instanceof DuplicateCustomerEmailException ? $e->getEmail()->getValue() : ''] ), ], CustomerDefaultGroupAccessException::class => $this->trans( 'A default customer group must be selected in group box.', + [], 'Admin.Orderscustomers.Notification' ), CustomerByEmailNotFoundException::class => $this->trans( 'This email address is not registered.', + [], 'Admin.Orderscustomers.Notification' ), CustomerConstraintException::class => [ CustomerConstraintException::INVALID_PASSWORD => $this->trans( 'Password should be at least %length% characters long.', + ['%length%' => Password::MIN_LENGTH], 'Admin.Orderscustomers.Help', - ['%length%' => Password::MIN_LENGTH] ), CustomerConstraintException::INVALID_FIRST_NAME => $this->trans( 'The %s field is invalid.', + [sprintf('"%s"', $this->trans('First name', [], 'Admin.Global'))], 'Admin.Notifications.Error', - [sprintf('"%s"', $this->trans('First name', 'Admin.Global'))] ), CustomerConstraintException::INVALID_LAST_NAME => $this->trans( 'The %s field is invalid.', + [sprintf('"%s"', $this->trans('Last name', [], 'Admin.Global'))], 'Admin.Notifications.Error', - [sprintf('"%s"', $this->trans('Last name', 'Admin.Global'))] ), CustomerConstraintException::INVALID_EMAIL => $this->trans( 'The %s field is invalid.', + [sprintf('"%s"', $this->trans('Email', [], 'Admin.Global'))], 'Admin.Notifications.Error', - [sprintf('"%s"', $this->trans('Email', 'Admin.Global'))] ), CustomerConstraintException::INVALID_BIRTHDAY => $this->trans( 'The %s field is invalid.', + [sprintf('"%s"', $this->trans('Birthday', [], 'Admin.Orderscustomers.Feature'))], 'Admin.Notifications.Error', - [sprintf('"%s"', $this->trans('Birthday', 'Admin.Orderscustomers.Feature'))] ), CustomerConstraintException::INVALID_APE_CODE => $this->trans( 'The %s field is invalid.', + [sprintf('"%s"', $this->trans('APE', [], 'Admin.Orderscustomers.Feature'))], 'Admin.Notifications.Error', - [sprintf('"%s"', $this->trans('APE', 'Admin.Orderscustomers.Feature'))] ), ], CustomerTransformationException::class => [ CustomerTransformationException::CUSTOMER_IS_NOT_GUEST => $this->trans( 'This customer already exists as a non-guest.', - 'Admin.Orderscustomers.Notification' + [], + 'Admin.Orderscustomers.Notification', ), CustomerTransformationException::TRANSFORMATION_FAILED => $this->trans( 'An error occurred while updating customer information.', - 'Admin.Orderscustomers.Notification' + [], + 'Admin.Orderscustomers.Notification', ), ], MissingCustomerRequiredFieldsException::class => $this->trans( 'The %s field is required.', - 'Admin.Notifications.Error', [ implode( ',', $e instanceof MissingCustomerRequiredFieldsException ? $e->getMissingRequiredFields() : [] ), - ] + ], + 'Admin.Notifications.Error', ), ]; } @@ -988,11 +1027,11 @@ private function getErrorMessages(Exception $e) * * @param int $messageId The message id from legacy context */ - private function manageLegacyFlashes($messageId) + private function manageLegacyFlashes($messageId): void { $messages = [ - 1 => $this->trans('Successful deletion', 'Admin.Notifications.Success'), - 4 => $this->trans('Update successful.', 'Admin.Notifications.Success'), + 1 => $this->trans('Successful deletion', [], 'Admin.Notifications.Success'), + 4 => $this->trans('Update successful.', [], 'Admin.Notifications.Success'), ]; if (isset($messages[$messageId])) { @@ -1010,11 +1049,11 @@ private function getCustomerIndexToolbarButtons(): array { $toolbarButtons = []; - $isSingleShopContext = $this->get('prestashop.adapter.shop.context')->isSingleShopContext(); + $isSingleShopContext = $this->getShopContext()->getShopConstraint()->isSingleShopContext(); $toolbarButtons['add'] = [ 'href' => $this->generateUrl('admin_customers_create'), - 'desc' => $this->trans('Add new customer', 'Admin.Orderscustomers.Feature'), + 'desc' => $this->trans('Add new customer', [], 'Admin.Orderscustomers.Feature'), 'icon' => 'add_circle_outline', 'disabled' => !$isSingleShopContext, ]; @@ -1022,6 +1061,7 @@ private function getCustomerIndexToolbarButtons(): array if (!$isSingleShopContext) { $toolbarButtons['add']['help'] = $this->trans( 'You can use this feature in a single-store context only. Switch contexts to enable it.', + [], 'Admin.Orderscustomers.Feature' ); $toolbarButtons['add']['href'] = '#'; @@ -1041,7 +1081,7 @@ private function getCustomerViewToolbarButtons(int $customerId): array $toolbarButtons['edit'] = [ 'href' => $this->generateUrl('admin_customers_edit', ['customerId' => $customerId]), - 'desc' => $this->trans('Edit customer', 'Admin.Orderscustomers.Feature'), + 'desc' => $this->trans('Edit customer', [], 'Admin.Orderscustomers.Feature'), 'icon' => 'mode_edit', ]; diff --git a/src/PrestaShopBundle/Resources/config/services/core/b2b.yml b/src/PrestaShopBundle/Resources/config/services/core/b2b.yml index 78a81848ecf70..35e398bad7216 100644 --- a/src/PrestaShopBundle/Resources/config/services/core/b2b.yml +++ b/src/PrestaShopBundle/Resources/config/services/core/b2b.yml @@ -2,7 +2,14 @@ services: _defaults: public: true - prestashop.core.b2b.b2b_feature: - class: 'PrestaShop\PrestaShop\Core\B2b\B2bFeature' + PrestaShop\PrestaShop\Core\B2b\B2bFeature: + public: false arguments: - '@prestashop.adapter.legacy.configuration' + + prestashop.core.b2b.b2b_feature: + alias: 'PrestaShop\PrestaShop\Core\B2b\B2bFeature' + public: true + deprecated: + package: PrestaShop\PrestaShop + version: 9.0 diff --git a/src/PrestaShopBundle/Resources/config/services/core/grid/grid_data_factory.yml b/src/PrestaShopBundle/Resources/config/services/core/grid/grid_data_factory.yml index 4819f87c37bb4..3f3544ad3ab8b 100644 --- a/src/PrestaShopBundle/Resources/config/services/core/grid/grid_data_factory.yml +++ b/src/PrestaShopBundle/Resources/config/services/core/grid/grid_data_factory.yml @@ -95,8 +95,6 @@ services: prestashop.core.grid.data_provider.customer_discount: class: 'PrestaShop\PrestaShop\Core\Grid\Data\Factory\CustomerDiscountGridDataFactory' - arguments: - - "@=service('prestashop.adapter.legacy.context').getContext().customer" prestashop.core.grid.data_provider.customer_address: class: '%prestashop.core.grid.data.factory.doctrine_grid_data_factory%' From ce5007ef4d264f33ccff683f7c5ebeb0325ea24f Mon Sep 17 00:00:00 2001 From: Jonathan LELIEVRE Date: Tue, 29 Oct 2024 10:37:15 +0100 Subject: [PATCH 5/6] Handle PrestaShopAdminController in automatic controller hook --- .../EventListener/ActionDispatcherLegacyHooksSubscriber.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PrestaShopBundle/EventListener/ActionDispatcherLegacyHooksSubscriber.php b/src/PrestaShopBundle/EventListener/ActionDispatcherLegacyHooksSubscriber.php index 9f910caf78d73..104d613c5f2b5 100644 --- a/src/PrestaShopBundle/EventListener/ActionDispatcherLegacyHooksSubscriber.php +++ b/src/PrestaShopBundle/EventListener/ActionDispatcherLegacyHooksSubscriber.php @@ -28,6 +28,7 @@ use PrestaShop\PrestaShop\Core\Hook\HookDispatcherInterface; use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; +use PrestaShopBundle\Controller\Admin\PrestaShopAdminController; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\ControllerEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; @@ -84,7 +85,7 @@ public function callActionDispatcherBeforeHook(ControllerEvent $event) : $event->getController() ; - if ($controller instanceof FrameworkBundleAdminController) { + if ($controller instanceof FrameworkBundleAdminController || $controller instanceof PrestaShopAdminController) { $controllerType = self::BACK_OFFICE_CONTROLLER; } From cbe84b475304a71d58db14336e8cb51f70743c76 Mon Sep 17 00:00:00 2001 From: Jonathan LELIEVRE Date: Tue, 29 Oct 2024 10:39:52 +0100 Subject: [PATCH 6/6] Refacto test controllers based on PrestaShopAdminController --- .../modules/demo/src/Controller/Admin/DemoController.php | 7 ++++--- .../src/Controller/Admin/ExempleController.php | 9 +++++---- .../src/Controller/Admin/ExempleController.php | 9 +++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/Resources/modules/demo/src/Controller/Admin/DemoController.php b/tests/Resources/modules/demo/src/Controller/Admin/DemoController.php index 31a8ee8da6c8e..2560cd898ae0c 100644 --- a/tests/Resources/modules/demo/src/Controller/Admin/DemoController.php +++ b/tests/Resources/modules/demo/src/Controller/Admin/DemoController.php @@ -26,11 +26,12 @@ namespace PsTest\Controller\Admin; -use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; +use PrestaShopBundle\Controller\Admin\PrestaShopAdminController; +use Symfony\Component\HttpFoundation\Response; -class DemoController extends FrameworkBundleAdminController +class DemoController extends PrestaShopAdminController { - public function demoAction() + public function demoAction(): Response { return $this->render('@Modules/demo/templates/admin/demo.html.twig'); } diff --git a/tests/Resources/modules/translationtest/src/Controller/Admin/ExempleController.php b/tests/Resources/modules/translationtest/src/Controller/Admin/ExempleController.php index 9ccb88f100eae..7675c4ce4cca1 100644 --- a/tests/Resources/modules/translationtest/src/Controller/Admin/ExempleController.php +++ b/tests/Resources/modules/translationtest/src/Controller/Admin/ExempleController.php @@ -26,14 +26,15 @@ namespace PrestaShop\Module\TranslationTest\Controller\Admin; -use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; +use PrestaShopBundle\Controller\Admin\PrestaShopAdminController; +use Symfony\Component\HttpFoundation\Response; -class ExempleController extends FrameworkBundleAdminController +class ExempleController extends PrestaShopAdminController { - public function indexAction() + public function indexAction(): Response { return $this->render('@Modules/translationtest/views/templates/admin/index.html.twig', [ - 'layoutTitle' => $this->trans('Modern controller', 'Modules.Translationtest.Admin'), + 'layoutTitle' => $this->trans('Modern controller', [], 'Modules.Translationtest.Admin'), 'help_link' => false, ]); } diff --git a/tests/Resources/modules/xlftranslatedmodule/src/Controller/Admin/ExempleController.php b/tests/Resources/modules/xlftranslatedmodule/src/Controller/Admin/ExempleController.php index a3bd033d44ca1..5b7a5cdbe9562 100644 --- a/tests/Resources/modules/xlftranslatedmodule/src/Controller/Admin/ExempleController.php +++ b/tests/Resources/modules/xlftranslatedmodule/src/Controller/Admin/ExempleController.php @@ -26,14 +26,15 @@ namespace PrestaShop\Module\Xlftranslatedmodule\Controller\Admin; -use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; +use PrestaShopBundle\Controller\Admin\PrestaShopAdminController; +use Symfony\Component\HttpFoundation\Response; -class ExempleController extends FrameworkBundleAdminController +class ExempleController extends PrestaShopAdminController { - public function indexAction() + public function indexAction(): Response { return $this->render('@Modules/xlftranslatedmodule/views/templates/admin/index.html.twig', [ - 'layoutTitle' => $this->trans('Modern controller', 'Modules.Xlftranslatedmodule.Admin'), + 'layoutTitle' => $this->trans('Modern controller', [], 'Modules.Xlftranslatedmodule.Admin'), 'help_link' => false, ]); }