diff --git a/phpstan-disallowed-calls.neon b/phpstan-disallowed-calls.neon index 926601fed88b4..b98eff356e61f 100644 --- a/phpstan-disallowed-calls.neon +++ b/phpstan-disallowed-calls.neon @@ -267,6 +267,7 @@ parameters: allowIn: - src/Adapter/* - src/PrestaShopBundle/Install/* + - src/PrestaShopBundle/Controller/Admin/Improve/Design/PositionsController.php - class: 'Symfony\Component\Translation\TranslatorInterface' message: 'use Symfony\Contracts\Translation\TranslatorInterface instead' @@ -293,6 +294,8 @@ parameters: - src/PrestaShopBundle/Controller/Admin/Sell/Catalog/Product/ProductController.php - src/PrestaShopBundle/Controller/Admin/Configure/ShopParameters/MetaController.php - src/PrestaShopBundle/Controller/Admin/Configure/ShopParameters/OrderStateController.php + - src/PrestaShopBundle/Controller/Admin/Improve/Design/CmsPageController.php + - src/PrestaShopBundle/Controller/Admin/Improve/Design/MailThemeController.php disallowedConstants: - constant: @@ -423,3 +426,8 @@ parameters: - src/* - classes/* - controllers/* + ignoreErrors: + - + message: "#^Namespace Module is forbidden, No legacy calls inside the prestashop bundle\\. Please create an interface and an adapter if you need to\\.$#" + count: 1 + path: src/PrestaShopBundle/Controller/Admin/Improve/Design/PositionsController.php diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Design/CmsPageController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Design/CmsPageController.php index 3217501b9ab63..fbe71a896e87e 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Design/CmsPageController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Design/CmsPageController.php @@ -27,6 +27,8 @@ namespace PrestaShopBundle\Controller\Admin\Improve\Design; use Exception; +use PrestaShop\PrestaShop\Adapter\Shop\Url\CmsProvider; +use PrestaShop\PrestaShop\Core\CMS\CmsPageViewDataProviderInterface; use PrestaShop\PrestaShop\Core\Domain\CmsPage\Command\BulkDeleteCmsPageCommand; use PrestaShop\PrestaShop\Core\Domain\CmsPage\Command\BulkDisableCmsPageCommand; use PrestaShop\PrestaShop\Core\Domain\CmsPage\Command\BulkEnableCmsPageCommand; @@ -59,17 +61,17 @@ use PrestaShop\PrestaShop\Core\Form\IdentifiableObject\Handler\FormHandlerInterface; use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\CmsPageCategoryDefinitionFactory; use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\CmsPageDefinitionFactory; +use PrestaShop\PrestaShop\Core\Grid\GridFactoryInterface; use PrestaShop\PrestaShop\Core\Grid\Position\Exception\PositionDataException; use PrestaShop\PrestaShop\Core\Grid\Position\Exception\PositionUpdateException; -use PrestaShop\PrestaShop\Core\Grid\Position\GridPositionUpdaterInterface; -use PrestaShop\PrestaShop\Core\Grid\Position\PositionUpdateFactoryInterface; +use PrestaShop\PrestaShop\Core\Grid\Position\PositionDefinition; use PrestaShop\PrestaShop\Core\Search\Filters\CmsPageCategoryFilters; use PrestaShop\PrestaShop\Core\Search\Filters\CmsPageFilters; use PrestaShop\PrestaShop\Core\Util\HelperCard\DocumentationLinkProviderInterface; -use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; +use PrestaShopBundle\Controller\Admin\PrestaShopAdminController; use PrestaShopBundle\Security\Attribute\AdminSecurity; use PrestaShopBundle\Security\Attribute\DemoRestricted; -use PrestaShopBundle\Service\Grid\ResponseBuilder; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -77,8 +79,16 @@ /** * Class CmsPageController is responsible for handling the logic in "Improve -> Design -> pages" page. */ -class CmsPageController extends FrameworkBundleAdminController +class CmsPageController extends PrestaShopAdminController { + public static function getSubscribedServices(): array + { + return parent::getSubscribedServices() + [ + CmsPageCategoryDefinitionFactory::GRID_ID => CmsPageCategoryDefinitionFactory::class, + CmsPageDefinitionFactory::GRID_ID => CmsPageDefinitionFactory::class, + ]; + } + /** * Responsible for displaying page content. * @@ -89,25 +99,31 @@ class CmsPageController extends FrameworkBundleAdminController * @return Response */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller'))")] - public function indexAction(CmsPageCategoryFilters $categoryFilters, CmsPageFilters $cmsFilters, Request $request) - { + public function indexAction( + CmsPageCategoryFilters $categoryFilters, + CmsPageFilters $cmsFilters, + Request $request, + DocumentationLinkProviderInterface $helperBlockLinkProvider, + #[Autowire(service: 'prestashop.core.cms_page.data_provider.cms_page_view')] + CmsPageViewDataProviderInterface $cmsPageViewDataProvider, + #[Autowire(service: 'prestashop.core.grid.factory.cms_page_category')] + GridFactoryInterface $cmsCategoryGridFactory, + #[Autowire(service: 'prestashop.core.grid.factory.cms_page')] + GridFactoryInterface $cmsGridFactory, + ): Response { $cmsCategoryParentId = (int) $categoryFilters->getFilters()['id_cms_category_parent']; - $viewData = $this->get('prestashop.core.cms_page.data_provider.cms_page_view')->getView($cmsCategoryParentId); - $cmsCategoryGridFactory = $this->get('prestashop.core.grid.factory.cms_page_category'); + $viewData = $cmsPageViewDataProvider->getView($cmsCategoryParentId); $cmsCategoryGrid = $cmsCategoryGridFactory->getGrid($categoryFilters); - $cmsGridFactory = $this->get('prestashop.core.grid.factory.cms_page'); $cmsGrid = $cmsGridFactory->getGrid($cmsFilters); - $showcaseCardIsClosed = $this->getQueryBus()->handle( + $showcaseCardIsClosed = $this->dispatchQuery( new GetShowcaseCardIsClosed( - (int) $this->getContext()->employee->id, + (int) $this->getEmployeeContext()->getEmployee()->getId(), ShowcaseCard::CMS_PAGES_CARD ) ); - $helperBlockLinkProvider = $this->get(DocumentationLinkProviderInterface::class); - return $this->render( '@PrestaShop/Admin/Improve/Design/Cms/index.html.twig', [ @@ -132,20 +148,15 @@ public function indexAction(CmsPageCategoryFilters $categoryFilters, CmsPageFilt * @return RedirectResponse */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller'))")] - public function searchAction(Request $request) + public function searchAction(Request $request): RedirectResponse { - $gridDefinitionFactory = 'prestashop.core.grid.definition.factory.cms_page_category'; $filterId = CmsPageCategoryDefinitionFactory::GRID_ID; if ($request->request->has(CmsPageDefinitionFactory::GRID_ID)) { - $gridDefinitionFactory = 'prestashop.core.grid.definition.factory.cms_page'; $filterId = CmsPageDefinitionFactory::GRID_ID; } - /** @var ResponseBuilder $responseBuilder */ - $responseBuilder = $this->get('prestashop.bundle.grid.response_builder'); - - return $responseBuilder->buildSearchResponse( - $this->get($gridDefinitionFactory), + return $this->buildSearchResponse( + $this->container->get($filterId), $request, $filterId, 'admin_cms_pages_index', @@ -163,27 +174,33 @@ public function searchAction(Request $request) * @return Response */ #[AdminSecurity("is_granted('create', request.get('_legacy_controller'))", redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'], message: 'You do not have permission to add this.')] - public function createAction(Request $request) - { - $formBuilder = $this->getCmsPageFormBuilder(); + public function createAction( + Request $request, + #[Autowire(service: 'prestashop.adapter.shop.url.cms_provider')] + CmsProvider $urlProvider, + #[Autowire(service: 'prestashop.core.form.identifiable_object.builder.cms_page_form_builder')] + FormBuilderInterface $cmsPageFormBuilder, + #[Autowire(service: 'prestashop.core.form.identifiable_object.handler.cms_page_form_handler')] + FormHandlerInterface $cmsPageFormHandler, + ): Response { $categoryParentId = $request->query->get('id_cms_category'); $formData = []; if ($categoryParentId) { $formData['page_category_id'] = $categoryParentId; } - $form = $formBuilder->getForm($formData, [ - 'cms_preview_url' => $this->get('prestashop.adapter.shop.url.cms_provider')->getUrl(0, '{friendly-url}'), + $form = $cmsPageFormBuilder->getForm($formData, [ + 'cms_preview_url' => $urlProvider->getUrl(0, '{friendly-url}'), ]); $form->handleRequest($request); try { - $result = $this->getCmsPageFormHandler()->handle($form); + $result = $cmsPageFormHandler->handle($form); $cmsPageId = $result->getIdentifiableObjectId(); if (null !== $cmsPageId) { $this->addFlash( 'success', - $this->trans('Successful creation', 'Admin.Notifications.Success') + $this->trans('Successful creation', [], 'Admin.Notifications.Success') ); if (!$request->request->has('save-and-preview')) { return $this->redirectToParentIndexPageByCmsPageId($cmsPageId); @@ -208,7 +225,7 @@ public function createAction(Request $request) 'cmsCategoryParentId' => $categoryParentId, 'enableSidebar' => true, 'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')), - 'layoutTitle' => $this->trans('New page', 'Admin.Navigation.Menu'), + 'layoutTitle' => $this->trans('New page', [], 'Admin.Navigation.Menu'), ] ); } @@ -220,21 +237,28 @@ public function createAction(Request $request) * @return Response */ #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'], message: 'You do not have permission to edit this.')] - public function editAction(Request $request, $cmsPageId) - { + public function editAction( + Request $request, + int $cmsPageId, + #[Autowire(service: 'prestashop.adapter.shop.url.cms_provider')] + CmsProvider $urlProvider, + #[Autowire(service: 'prestashop.core.form.identifiable_object.builder.cms_page_form_builder')] + FormBuilderInterface $cmsPageFormBuilder, + #[Autowire(service: 'prestashop.core.form.identifiable_object.handler.cms_page_form_handler')] + FormHandlerInterface $cmsPageFormHandler, + ): Response { $cmsPageId = (int) $cmsPageId; try { /** @var EditableCmsPage $editableCmsPage */ - $editableCmsPage = $this->getQueryBus()->handle(new GetCmsPageForEditing($cmsPageId)); + $editableCmsPage = $this->dispatchQuery(new GetCmsPageForEditing($cmsPageId)); $previewUrl = $editableCmsPage->getPreviewUrl(); - $form = $this->getCmsPageFormBuilder()->getFormFor($cmsPageId, [], [ + $form = $cmsPageFormBuilder->getFormFor($cmsPageId, [], [ 'action' => $this->generateUrl('admin_cms_pages_edit', [ 'cmsPageId' => $cmsPageId, ]), - 'cms_preview_url' => $this->get('prestashop.adapter.shop.url.cms_provider') - ->getUrl($cmsPageId, '{friendly-url}'), + 'cms_preview_url' => $urlProvider->getUrl($cmsPageId, '{friendly-url}'), ]); $form->handleRequest($request); } catch (Exception $e) { @@ -247,12 +271,12 @@ public function editAction(Request $request, $cmsPageId) } try { - $result = $this->getCmsPageFormHandler()->handleFor($cmsPageId, $form); + $result = $cmsPageFormHandler->handleFor($cmsPageId, $form); if ($result->isSubmitted() && $result->isValid()) { $this->addFlash( 'success', - $this->trans('Successful update', 'Admin.Notifications.Success') + $this->trans('Successful update', [], 'Admin.Notifications.Success') ); if ($request->request->has('save-and-preview')) { @@ -282,10 +306,10 @@ public function editAction(Request $request, $cmsPageId) 'previewUrl' => $previewUrl, 'layoutTitle' => $this->trans( 'Editing page %name%', - 'Admin.Navigation.Menu', [ - '%name%' => $editableCmsPage->getLocalizedTitle()[$this->getContextLangId()], - ] + '%name%' => $editableCmsPage->getLocalizedTitle()[$this->getLanguageContext()->getId()], + ], + 'Admin.Navigation.Menu' ), ] ); @@ -299,20 +323,24 @@ public function editAction(Request $request, $cmsPageId) * @return Response */ #[AdminSecurity("is_granted('create', request.get('_legacy_controller'))", redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'], message: 'You do not have permission to add this.')] - public function createCmsCategoryAction(Request $request) - { - $cmsPageCategoryFormBuilder = $this->getCmsPageCategoryFormBuilder(); + public function createCmsCategoryAction( + Request $request, + #[Autowire(service: 'prestashop.core.form.identifiable_object.builder.cms_page_category_form_builder')] + FormBuilderInterface $cmsPageCategoryFormBuilder, + #[Autowire(service: 'prestashop.core.form.identifiable_object.handler.cms_page_category_form_handler')] + FormHandlerInterface $cmsPageCategoryFormHandler, + ): Response { $cmsPageCategoryForm = $cmsPageCategoryFormBuilder->getForm(); $cmsPageCategoryForm->handleRequest($request); try { - $result = $this->getCmsPageCategoryFormHandler()->handle($cmsPageCategoryForm); + $result = $cmsPageCategoryFormHandler->handle($cmsPageCategoryForm); if (null !== $result->getIdentifiableObjectId()) { $this->addFlash( 'success', - $this->trans('Successful creation', 'Admin.Notifications.Success') + $this->trans('Successful creation', [], 'Admin.Notifications.Success') ); return $this->redirectToIndexPageById($result->getIdentifiableObjectId()); @@ -330,7 +358,7 @@ public function createCmsCategoryAction(Request $request) 'cmsPageCategoryForm' => $cmsPageCategoryForm->createView(), 'enableSidebar' => true, 'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')), - 'layoutTitle' => $this->trans('New category', 'Admin.Navigation.Menu'), + 'layoutTitle' => $this->trans('New category', [], 'Admin.Navigation.Menu'), ] ); } @@ -344,10 +372,14 @@ public function createCmsCategoryAction(Request $request) * @return Response */ #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'], message: 'You do not have permission to edit this.')] - public function editCmsCategoryAction($cmsCategoryId, Request $request) - { - $cmsPageCategoryFormBuilder = $this->getCmsPageCategoryFormBuilder(); - + public function editCmsCategoryAction( + int $cmsCategoryId, + Request $request, + #[Autowire(service: 'prestashop.core.form.identifiable_object.builder.cms_page_category_form_builder')] + FormBuilderInterface $cmsPageCategoryFormBuilder, + #[Autowire(service: 'prestashop.core.form.identifiable_object.handler.cms_page_category_form_handler')] + FormHandlerInterface $cmsPageCategoryFormHandler, + ): Response { try { $cmsPageCategoryForm = $cmsPageCategoryFormBuilder->getFormFor((int) $cmsCategoryId); $cmsCategoryParentId = $this->getParentCategoryId((int) $cmsCategoryId)->getValue(); @@ -362,12 +394,12 @@ public function editCmsCategoryAction($cmsCategoryId, Request $request) try { $cmsPageCategoryForm->handleRequest($request); - $result = $this->getCmsPageCategoryFormHandler()->handleFor((int) $cmsCategoryId, $cmsPageCategoryForm); + $result = $cmsPageCategoryFormHandler->handleFor((int) $cmsCategoryId, $cmsPageCategoryForm); if ($result->isSubmitted() && $result->isValid()) { $this->addFlash( 'success', - $this->trans('Successful update', 'Admin.Notifications.Success') + $this->trans('Successful update', [], 'Admin.Notifications.Success') ); return $this->redirectToIndexPageById($result->getIdentifiableObjectId()); @@ -392,10 +424,10 @@ public function editCmsCategoryAction($cmsCategoryId, Request $request) 'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')), 'layoutTitle' => $this->trans( 'Editing category %name%', - 'Admin.Navigation.Menu', [ - '%name%' => $cmsPageCategoryForm->getData()['name'][$this->getContextLangId()], - ] + '%name%' => $cmsPageCategoryForm->getData()['name'][$this->getLanguageContext()->getId()], + ], + 'Admin.Navigation.Menu' ), ] ); @@ -410,16 +442,16 @@ public function editCmsCategoryAction($cmsCategoryId, Request $request) */ #[DemoRestricted(redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'])] #[AdminSecurity("is_granted('delete', request.get('_legacy_controller'))", redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'], message: 'You do not have permission to delete this.')] - public function deleteCmsCategoryAction($cmsCategoryId) + public function deleteCmsCategoryAction(int $cmsCategoryId): RedirectResponse { try { - $this->getCommandBus()->handle( + $this->dispatchCommand( new DeleteCmsPageCategoryCommand((int) $cmsCategoryId) ); $this->addFlash( 'success', - $this->trans('Successful deletion', 'Admin.Notifications.Success') + $this->trans('Successful deletion', [], 'Admin.Notifications.Success') ); } catch (Exception $exception) { $this->addFlash( @@ -440,20 +472,20 @@ public function deleteCmsCategoryAction($cmsCategoryId) */ #[DemoRestricted(redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'])] #[AdminSecurity("is_granted('delete', request.get('_legacy_controller'))", redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'], message: 'You do not have permission to delete this.')] - public function deleteBulkCmsCategoryAction(Request $request) + public function deleteBulkCmsCategoryAction(Request $request): RedirectResponse { $cmsCategoriesToDelete = $request->request->all('cms_page_category_bulk'); try { $cmsCategoriesToDelete = array_map(function ($item) { return (int) $item; }, $cmsCategoriesToDelete); - $this->getCommandBus()->handle( + $this->dispatchCommand( new BulkDeleteCmsPageCategoryCommand($cmsCategoriesToDelete) ); $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 (Exception $exception) { $this->addFlash( @@ -474,8 +506,11 @@ public function deleteBulkCmsCategoryAction(Request $request) */ #[DemoRestricted(redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'])] #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'], message: 'You do not have permission to edit this.')] - public function updateCmsCategoryPositionAction(Request $request) - { + public function updateCmsCategoryPositionAction( + Request $request, + #[Autowire(service: 'prestashop.core.grid.cms_page_category.position_definition')] + PositionDefinition $positionDefinition + ): RedirectResponse { $cmsCategoryParentId = $request->query->getInt('id_cms_category') ?: CmsPageCategoryId::ROOT_CMS_PAGE_CATEGORY_ID ; @@ -485,27 +520,17 @@ public function updateCmsCategoryPositionAction(Request $request) 'parentId' => $cmsCategoryParentId, ]; - $positionDefinition = $this->get('prestashop.core.grid.cms_page_category.position_definition'); - - $positionUpdateFactory = $this->get(PositionUpdateFactoryInterface::class); - try { - $positionUpdate = $positionUpdateFactory->buildPositionUpdate($positionsData, $positionDefinition); + $this->updateGridPosition($positionDefinition, $positionsData); + $this->addFlash('success', $this->trans('Successful update', [], 'Admin.Notifications.Success')); } catch (PositionDataException $e) { $errors = [$e->toArray()]; - $this->flashErrors($errors); + $this->addFlashErrors($errors); return $this->redirectToIndexPageById($cmsCategoryParentId); - } - - $updater = $this->get(GridPositionUpdaterInterface::class); - - try { - $updater->update($positionUpdate); - $this->addFlash('success', $this->trans('Successful update', 'Admin.Notifications.Success')); } catch (PositionUpdateException $e) { $errors = [$e->toArray()]; - $this->flashErrors($errors); + $this->addFlashErrors($errors); } return $this->redirectToIndexPageById($cmsCategoryParentId); @@ -518,8 +543,11 @@ public function updateCmsCategoryPositionAction(Request $request) */ #[DemoRestricted(redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'])] #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'], message: 'You do not have permission to edit this.')] - public function updateCmsPositionAction(Request $request) - { + public function updateCmsPositionAction( + Request $request, + #[Autowire(service: 'prestashop.core.grid.cms_page.position_definition')] + PositionDefinition $positionDefinition + ): RedirectResponse { $cmsCategoryParentId = $request->query->getInt('id_cms_category') ?: CmsPageCategoryId::ROOT_CMS_PAGE_CATEGORY_ID ; @@ -529,26 +557,17 @@ public function updateCmsPositionAction(Request $request) 'parentId' => $cmsCategoryParentId, ]; - $positionDefinition = $this->get('prestashop.core.grid.cms_page.position_definition'); - $positionUpdateFactory = $this->get(PositionUpdateFactoryInterface::class); - try { - $positionUpdate = $positionUpdateFactory->buildPositionUpdate($positionsData, $positionDefinition); + $this->updateGridPosition($positionDefinition, $positionsData); + $this->addFlash('success', $this->trans('Successful update', [], 'Admin.Notifications.Success')); } catch (PositionDataException $e) { $errors = [$e->toArray()]; - $this->flashErrors($errors); + $this->addFlashErrors($errors); return $this->redirectToParentIndexPage($cmsCategoryParentId); - } - - $updater = $this->get(GridPositionUpdaterInterface::class); - - try { - $updater->update($positionUpdate); - $this->addFlash('success', $this->trans('Successful update', 'Admin.Notifications.Success')); } catch (PositionUpdateException $e) { $errors = [$e->toArray()]; - $this->flashErrors($errors); + $this->addFlashErrors($errors); } return $this->redirectToIndexPageById($cmsCategoryParentId); @@ -563,16 +582,16 @@ public function updateCmsPositionAction(Request $request) */ #[DemoRestricted(redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'])] #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'], message: 'You do not have permission to edit this.')] - public function toggleCmsCategoryAction($cmsCategoryId) + public function toggleCmsCategoryAction($cmsCategoryId): RedirectResponse { try { - $this->getCommandBus()->handle( + $this->dispatchCommand( new ToggleCmsPageCategoryStatusCommand((int) $cmsCategoryId) ); $this->addFlash( 'success', - $this->trans('The status has been successfully updated.', 'Admin.Notifications.Success') + $this->trans('The status has been successfully updated.', [], 'Admin.Notifications.Success') ); } catch (Exception $exception) { $this->addFlash( @@ -593,19 +612,19 @@ public function toggleCmsCategoryAction($cmsCategoryId) */ #[DemoRestricted(redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'])] #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'], message: 'You do not have permission to edit this.')] - public function bulkCmsPageCategoryStatusEnableAction(Request $request) + public function bulkCmsPageCategoryStatusEnableAction(Request $request): RedirectResponse { $cmsCategoriesToEnable = $request->request->all('cms_page_category_bulk'); try { $cmsCategoriesToEnable = array_map(function ($item) { return (int) $item; }, $cmsCategoriesToEnable); - $this->getCommandBus()->handle( + $this->dispatchCommand( new BulkEnableCmsPageCategoryCommand($cmsCategoriesToEnable) ); $this->addFlash( 'success', - $this->trans('The status has been successfully updated.', 'Admin.Notifications.Success') + $this->trans('The status has been successfully updated.', [], 'Admin.Notifications.Success') ); } catch (Exception $exception) { $this->addFlash( @@ -626,7 +645,7 @@ public function bulkCmsPageCategoryStatusEnableAction(Request $request) */ #[DemoRestricted(redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'])] #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'], message: 'You do not have permission to edit this.')] - public function bulkCmsPageCategoryStatusDisableAction(Request $request) + public function bulkCmsPageCategoryStatusDisableAction(Request $request): RedirectResponse { $cmsCategoriesToDisable = $request->request->all('cms_page_category_bulk'); try { @@ -636,13 +655,13 @@ function ($item) { }, $cmsCategoriesToDisable ); - $this->getCommandBus()->handle( + $this->dispatchCommand( new BulkDisableCmsPageCategoryCommand($cmsCategoriesToDisable) ); $this->addFlash( 'success', - $this->trans('The status has been successfully updated.', 'Admin.Notifications.Success') + $this->trans('The status has been successfully updated.', [], 'Admin.Notifications.Success') ); } catch (Exception $exception) { $this->addFlash( @@ -663,14 +682,14 @@ function ($item) { */ #[DemoRestricted(redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'])] #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'], message: 'You do not have permission to edit this.')] - public function toggleCmsAction($cmsId) + public function toggleCmsAction($cmsId): RedirectResponse { try { - $this->getCommandBus()->handle(new ToggleCmsPageStatusCommand((int) $cmsId)); + $this->dispatchCommand(new ToggleCmsPageStatusCommand((int) $cmsId)); $this->addFlash( 'success', - $this->trans('The status has been successfully updated.', 'Admin.Notifications.Success') + $this->trans('The status has been successfully updated.', [], 'Admin.Notifications.Success') ); } catch (Exception $exception) { $this->addFlash( @@ -691,20 +710,20 @@ public function toggleCmsAction($cmsId) */ #[DemoRestricted(redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'])] #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'], message: 'You do not have permission to edit this.')] - public function bulkDisableCmsPageStatusAction(Request $request) + public function bulkDisableCmsPageStatusAction(Request $request): RedirectResponse { $cmsPagesToDisable = $request->request->all('cms_page_bulk'); try { $cmsPagesToDisable = array_map(function ($item) { return (int) $item; }, $cmsPagesToDisable); - $this->getCommandBus()->handle( + $this->dispatchCommand( new BulkDisableCmsPageCommand($cmsPagesToDisable) ); $this->addFlash( 'success', - $this->trans('The status has been successfully updated.', 'Admin.Notifications.Success') + $this->trans('The status has been successfully updated.', [], 'Admin.Notifications.Success') ); } catch (Exception $exception) { $this->addFlash( @@ -725,7 +744,7 @@ public function bulkDisableCmsPageStatusAction(Request $request) */ #[DemoRestricted(redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'])] #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'], message: 'You do not have permission to edit this.')] - public function bulkEnableCmsPageStatusAction(Request $request) + public function bulkEnableCmsPageStatusAction(Request $request): RedirectResponse { $cmsPagesToDisable = $request->request->all('cms_page_bulk'); @@ -737,13 +756,13 @@ function ($item) { $cmsPagesToDisable ); - $this->getCommandBus()->handle( + $this->dispatchCommand( new BulkEnableCmsPageCommand($cmsPagesToDisable) ); $this->addFlash( 'success', - $this->trans('The status has been successfully updated.', 'Admin.Notifications.Success') + $this->trans('The status has been successfully updated.', [], 'Admin.Notifications.Success') ); } catch (Exception $exception) { $this->addFlash( @@ -764,7 +783,7 @@ function ($item) { */ #[DemoRestricted(redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'])] #[AdminSecurity("is_granted('delete', request.get('_legacy_controller'))", redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'], message: 'You do not have permission to delete this.')] - public function bulkDeleteCmsPageAction(Request $request) + public function bulkDeleteCmsPageAction(Request $request): RedirectResponse { $cmsPagesToDisable = $request->request->all('cms_page_bulk'); @@ -778,13 +797,13 @@ function ($item) { $cmsPagesToDisable ); - $this->getCommandBus()->handle( + $this->dispatchCommand( new BulkDeleteCmsPageCommand($cmsPagesToDisable) ); $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 (Exception $exception) { $this->addFlash( @@ -805,16 +824,16 @@ function ($item) { */ #[DemoRestricted(redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'])] #[AdminSecurity("is_granted('delete', request.get('_legacy_controller'))", redirectRoute: 'admin_cms_pages_index', redirectQueryParamsToKeep: ['id_cms_category'], message: 'You do not have permission to delete this.')] - public function deleteCmsAction($cmsId) + public function deleteCmsAction($cmsId): RedirectResponse { $redirectResponse = $this->redirectToParentIndexPageByCmsPageId($cmsId); try { - $this->getCommandBus()->handle(new DeleteCmsPageCommand((int) $cmsId)); + $this->dispatchCommand(new DeleteCmsPageCommand((int) $cmsId)); $this->addFlash( 'success', - $this->trans('Successful deletion', 'Admin.Notifications.Success') + $this->trans('Successful deletion', [], 'Admin.Notifications.Success') ); } catch (Exception $exception) { $this->addFlash( @@ -826,24 +845,6 @@ public function deleteCmsAction($cmsId) return $redirectResponse; } - /** - * Gets cms page category form builder. - * - * @return FormBuilderInterface - */ - private function getCmsPageCategoryFormBuilder() - { - return $this->get('prestashop.core.form.identifiable_object.builder.cms_page_category_form_builder'); - } - - /** - * @return FormHandlerInterface - */ - private function getCmsPageCategoryFormHandler() - { - return $this->get('prestashop.core.form.identifiable_object.handler.cms_page_category_form_handler'); - } - /** * This function is used for redirecting to the specific cms page category page. It uses bulk action ids which * share the same parent cms category in all cases. @@ -852,7 +853,7 @@ private function getCmsPageCategoryFormHandler() * * @return RedirectResponse */ - private function redirectToParentIndexPageByCategoryBulkIds(array $cmsPageCategoryIds) + private function redirectToParentIndexPageByCategoryBulkIds(array $cmsPageCategoryIds): RedirectResponse { if (empty($cmsPageCategoryIds)) { return $this->redirectToRoute('admin_cms_pages_index'); @@ -868,7 +869,7 @@ private function redirectToParentIndexPageByCategoryBulkIds(array $cmsPageCatego * * @return RedirectResponse */ - private function redirectToParentIndexPageByBulkIds(array $cmsPageIds) + private function redirectToParentIndexPageByBulkIds(array $cmsPageIds): RedirectResponse { if (empty($cmsPageIds)) { return $this->redirectToRoute('admin_cms_pages_index'); @@ -884,7 +885,7 @@ private function redirectToParentIndexPageByBulkIds(array $cmsPageIds) * * @return RedirectResponse */ - private function redirectToParentIndexPage($cmsPageCategoryId) + private function redirectToParentIndexPage($cmsPageCategoryId): RedirectResponse { try { $cmsPageCategoryParentId = $this->getParentCategoryId($cmsPageCategoryId)->getValue(); @@ -900,10 +901,10 @@ private function redirectToParentIndexPage($cmsPageCategoryId) * * @return RedirectResponse */ - private function redirectToParentIndexPageByCmsPageId($cmsPageId) + private function redirectToParentIndexPageByCmsPageId($cmsPageId): RedirectResponse { try { - $cmsCategoryId = $this->getQueryBus()->handle(new GetCmsCategoryIdForRedirection((int) $cmsPageId))->getValue(); + $cmsCategoryId = $this->dispatchQuery(new GetCmsCategoryIdForRedirection((int) $cmsPageId))->getValue(); } catch (CmsPageException $e) { $cmsCategoryId = CmsPageCategoryId::ROOT_CMS_PAGE_CATEGORY_ID; } @@ -918,7 +919,7 @@ private function redirectToParentIndexPageByCmsPageId($cmsPageId) * * @return RedirectResponse */ - private function redirectToIndexPageById($cmsPageCategoryId) + private function redirectToIndexPageById($cmsPageCategoryId): RedirectResponse { $routeParameters = []; @@ -940,32 +941,16 @@ private function redirectToIndexPageById($cmsPageCategoryId) * * @throws CmsPageCategoryException */ - private function getParentCategoryId($cmsPageCategoryChildId) + private function getParentCategoryId($cmsPageCategoryChildId): CmsPageCategoryId { /** @var CmsPageCategoryId $cmsPageCategoryParentId */ - $cmsPageCategoryParentId = $this->getQueryBus()->handle( + $cmsPageCategoryParentId = $this->dispatchQuery( new GetCmsPageParentCategoryIdForRedirection($cmsPageCategoryChildId) ); return $cmsPageCategoryParentId; } - /** - * @return FormBuilderInterface - */ - private function getCmsPageFormBuilder() - { - return $this->get('prestashop.core.form.identifiable_object.builder.cms_page_form_builder'); - } - - /** - * @return FormHandlerInterface - */ - private function getCmsPageFormHandler() - { - return $this->get('prestashop.core.form.identifiable_object.handler.cms_page_form_handler'); - } - /** * Provides translatable error messages for exceptions * @@ -976,108 +961,119 @@ private function getErrorMessages() return [ CmsPageNotFoundException::class => $this->trans( 'The object cannot be loaded (or found).', + [], 'Admin.Notifications.Error' ), CannotToggleCmsPageException::class => $this->trans( 'An error occurred while updating the status.', + [], 'Admin.Notifications.Error' ), CannotDisableCmsPageException::class => $this->trans( 'An error occurred while updating the status.', + [], 'Admin.Notifications.Error' ), CannotEnableCmsPageException::class => $this->trans( 'An error occurred while updating the status.', + [], 'Admin.Notifications.Error' ), CannotDeleteCmsPageException::class => [ CannotDeleteCmsPageException::FAILED_BULK_DELETE => $this->trans( 'An error occurred while deleting this selection.', + [], 'Admin.Notifications.Error' ), CannotDeleteCmsPageException::FAILED_DELETE => $this->trans( 'An error occurred while deleting the object.', + [], 'Admin.Notifications.Error' ), ], CmsPageCategoryConstraintException::class => [ CmsPageCategoryConstraintException::INVALID_BULK_DATA => $this->trans( 'You must select at least one element to delete.', + [], 'Admin.Notifications.Error' ), - CmsPageCategoryConstraintException::CANNOT_MOVE_CATEGORY_TO_PARENT => $this->trans('The page Category cannot be moved here.', 'Admin.Design.Notification'), + CmsPageCategoryConstraintException::CANNOT_MOVE_CATEGORY_TO_PARENT => $this->trans('The page Category cannot be moved here.', [], 'Admin.Design.Notification'), CmsPageCategoryConstraintException::MISSING_DEFAULT_LANGUAGE_FOR_NAME => $this->trans( 'The %s field is not valid', - 'Admin.Notifications.Error', [ - sprintf('"%s"', $this->trans('Name', 'Admin.Global')), - ] + sprintf('"%s"', $this->trans('Name', [], 'Admin.Global')), + ], + 'Admin.Notifications.Error' ), CmsPageCategoryConstraintException::MISSING_DEFAULT_LANGUAGE_FOR_FRIENDLY_URL => $this->trans( 'The %s field is not valid', - 'Admin.Notifications.Error', [ - sprintf('"%s"', $this->trans('Friendly URL', 'Admin.Global')), - ] + sprintf('"%s"', $this->trans('Friendly URL', [], 'Admin.Global')), + ], + 'Admin.Notifications.Error' ), CmsPageCategoryConstraintException::INVALID_CATEGORY_NAME => $this->trans( 'The %s field is not valid', - 'Admin.Notifications.Error', [ - sprintf('"%s"', $this->trans('Name', 'Admin.Global')), - ] + sprintf('"%s"', $this->trans('Name', [], 'Admin.Global')), + ], + 'Admin.Notifications.Error' ), CmsPageCategoryConstraintException::INVALID_LINK_REWRITE => $this->trans( 'The %s field is not valid', - 'Admin.Notifications.Error', [ - sprintf('"%s"', $this->trans('Friendly URL', 'Admin.Global')), - ] + sprintf('"%s"', $this->trans('Friendly URL', [], 'Admin.Global')), + ], + 'Admin.Notifications.Error' ), CmsPageCategoryConstraintException::INVALID_META_TITLE => $this->trans( 'The %s field is not valid', - 'Admin.Notifications.Error', [ - sprintf('"%s"', $this->trans('Meta title', 'Admin.Global')), - ] + sprintf('"%s"', $this->trans('Meta title', [], 'Admin.Global')), + ], + 'Admin.Notifications.Error' ), CmsPageCategoryConstraintException::INVALID_DESCRIPTION => $this->trans( 'The %s field is not valid', - 'Admin.Notifications.Error', [ - sprintf('"%s"', $this->trans('Description', 'Admin.Global')), - ] + sprintf('"%s"', $this->trans('Description', [], 'Admin.Global')), + ], + 'Admin.Notifications.Error' ), CmsPageCategoryConstraintException::INVALID_META_DESCRIPTION => $this->trans( 'The %s field is not valid', - 'Admin.Notifications.Error', [ - sprintf('"%s"', $this->trans('Meta description', 'Admin.Global')), - ] + sprintf('"%s"', $this->trans('Meta description', [], 'Admin.Global')), + ], + 'Admin.Notifications.Error' ), CmsPageCategoryConstraintException::INVALID_META_KEYWORDS => $this->trans( 'The %s field is not valid', - 'Admin.Notifications.Error', [ - sprintf('"%s"', $this->trans('Meta keywords', 'Admin.Global')), - ] + sprintf('"%s"', $this->trans('Meta keywords', [], 'Admin.Global')), + ], + 'Admin.Notifications.Error', ), ], CmsPageCategoryNotFoundException::class => $this->trans( 'The object cannot be loaded (or found).', + [], 'Admin.Notifications.Error' ), CannotToggleCmsPageCategoryStatusException::class => $this->trans( 'An error occurred while updating the status.', + [], 'Admin.Notifications.Error' ), CannotDeleteCmsPageCategoryException::class => [ CannotDeleteCmsPageCategoryException::FAILED_BULK_DELETE => $this->trans( 'An error occurred while deleting this selection.', + [], 'Admin.Notifications.Error' ), CannotDeleteCmsPageCategoryException::FAILED_DELETE => $this->trans( 'An error occurred while deleting the object.', + [], 'Admin.Notifications.Error' ), ], @@ -1096,20 +1092,20 @@ private function getCmsPageIndexToolbarButtons($cmsCategoryId): array if ($cmsCategoryId !== CmsPageCategoryId::ROOT_CMS_PAGE_CATEGORY_ID) { $toolbarButtons['edit_cms_category'] = [ 'href' => $this->generateUrl('admin_cms_pages_category_edit', ['cmsCategoryId' => $cmsCategoryId]), - 'desc' => $this->trans('Edit page category', 'Admin.Design.Help'), + 'desc' => $this->trans('Edit page category', [], 'Admin.Design.Help'), 'icon' => 'mode_edit', ]; } $toolbarButtons['add_cms_category'] = [ 'href' => $this->generateUrl('admin_cms_pages_category_create', ['id_cms_category' => $cmsCategoryId]), - 'desc' => $this->trans('Add new page category', 'Admin.Design.Help'), + 'desc' => $this->trans('Add new page category', [], 'Admin.Design.Help'), 'icon' => 'add_circle_outline', ]; $toolbarButtons['add_cms_page'] = [ 'href' => $this->generateUrl('admin_cms_pages_create', ['id_cms_category' => $cmsCategoryId]), - 'desc' => $this->trans('Add new page', 'Admin.Design.Help'), + 'desc' => $this->trans('Add new page', [], 'Admin.Design.Help'), 'icon' => 'add_circle_outline', ]; diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Design/ImageSettingsController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Design/ImageSettingsController.php index 7aa1821503dfe..7be5263a7b55d 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Design/ImageSettingsController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Design/ImageSettingsController.php @@ -36,11 +36,16 @@ use PrestaShop\PrestaShop\Core\Domain\ImageSettings\Exception\ImageTypeNotFoundException; use PrestaShop\PrestaShop\Core\Domain\ImageSettings\Query\GetImageTypeForEditing; use PrestaShop\PrestaShop\Core\Domain\ImageSettings\QueryResult\EditableImageType; +use PrestaShop\PrestaShop\Core\Form\FormHandlerInterface as ConfigurationFormHandlerInterface; +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\Search\Filters\ImageTypeFilters; -use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; +use PrestaShopBundle\Controller\Admin\PrestaShopAdminController; use PrestaShopBundle\Form\Admin\Improve\Design\ImageSettings\DeleteImageTypeType; use PrestaShopBundle\Form\Admin\Improve\Design\ImageSettings\RegenerateThumbnailsType; use PrestaShopBundle\Security\Attribute\AdminSecurity; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -48,7 +53,7 @@ /** * Responsible for Image Settings actions in Back Office */ -class ImageSettingsController extends FrameworkBundleAdminController +class ImageSettingsController extends PrestaShopAdminController { /** * Displays image settings listing page. @@ -59,18 +64,22 @@ class ImageSettingsController extends FrameworkBundleAdminController * @return Response */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller'))")] - public function indexAction(Request $request, ImageTypeFilters $filters): Response - { + public function indexAction( + Request $request, + ImageTypeFilters $filters, + #[Autowire(service: 'prestashop.core.grid.factory.image_type')] + GridFactoryInterface $imageTypeGridFactory, + #[Autowire(service: 'prestashop.admin.image_settings.form_handler')] + ConfigurationFormHandlerInterface $configFormHandler + ): Response { // Get image type grid - $imageTypeGridFactory = $this->get('prestashop.core.grid.factory.image_type'); $imageTypeGrid = $imageTypeGridFactory->getGrid($filters); // Create form for deleting image type if needed (in modal) $deleteForm = $this->createForm(DeleteImageTypeType::class); // Create form to set some image settings - $configFormBuilder = $this->get('prestashop.admin.image_settings.form_handler'); - $configForm = $configFormBuilder->getForm(); + $configForm = $configFormHandler->getForm(); // Create form to regenerate thumbnails $regenThumbnailsForm = $this->createForm(RegenerateThumbnailsType::class); @@ -83,7 +92,7 @@ public function indexAction(Request $request, ImageTypeFilters $filters): Respon 'layoutHeaderToolbarBtn' => [ 'add' => [ 'href' => $this->generateUrl('admin_image_settings_create'), - 'desc' => $this->trans('Add new image type', 'Admin.Design.Feature'), + 'desc' => $this->trans('Add new image type', [], 'Admin.Design.Feature'), 'icon' => 'add_circle_outline', ], ], @@ -93,18 +102,20 @@ public function indexAction(Request $request, ImageTypeFilters $filters): Respon } #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))")] - public function saveSettingsAction(Request $request): Response - { + public function saveSettingsAction( + Request $request, + #[Autowire(service: 'prestashop.admin.image_settings.form_handler')] + ConfigurationFormHandlerInterface $configFormHandler + ): Response { try { // Create form to set some image settings - $configFormHandler = $this->get('prestashop.admin.image_settings.form_handler'); $configForm = $configFormHandler->getForm(); $configForm->handleRequest($request); if ($configForm->isSubmitted()) { if ($configForm->isValid()) { $configFormHandler->save($configForm->getData()); - $this->addFlash('success', $this->trans('The settings have been successfully updated.', 'Admin.Notifications.Success')); + $this->addFlash('success', $this->trans('The settings have been successfully updated.', [], 'Admin.Notifications.Success')); } else { $this->addFlashFormErrors($configForm); } @@ -124,11 +135,13 @@ public function saveSettingsAction(Request $request): Response * @return Response */ #[AdminSecurity("is_granted('create', request.get('_legacy_controller'))", redirectRoute: 'admin_image_settings_index')] - public function createAction(Request $request): Response - { - $formBuilder = $this->get('prestashop.core.form.identifiable_object.builder.image_type_form_builder'); - $formHandler = $this->get('prestashop.core.form.identifiable_object.handler.image_type_form_handler'); - + public function createAction( + Request $request, + #[Autowire(service: 'prestashop.core.form.identifiable_object.builder.image_type_form_builder')] + FormBuilderInterface $formBuilder, + #[Autowire(service: 'prestashop.core.form.identifiable_object.handler.image_type_form_handler')] + FormHandlerInterface $formHandler, + ): Response { $form = $formBuilder->getForm(); $form->handleRequest($request); @@ -136,7 +149,7 @@ public function createAction(Request $request): Response $handleResult = $formHandler->handle($form); if ($handleResult->isSubmitted() && $handleResult->isValid()) { - $this->addFlash('success', $this->trans('Successful creation', 'Admin.Notifications.Success')); + $this->addFlash('success', $this->trans('Successful creation', [], 'Admin.Notifications.Success')); return $this->redirectToRoute('admin_image_settings_index'); } @@ -148,7 +161,7 @@ public function createAction(Request $request): Response 'form' => $form->createView(), 'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')), 'enableSidebar' => true, - 'layoutTitle' => $this->trans('Add new', 'Admin.Actions'), + 'layoutTitle' => $this->trans('Add new', [], 'Admin.Actions'), ]); } @@ -161,14 +174,17 @@ public function createAction(Request $request): Response * @return Response */ #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_image_settings_index')] - public function editAction(int $imageTypeId, Request $request): Response - { + public function editAction( + int $imageTypeId, + Request $request, + #[Autowire(service: 'prestashop.core.form.identifiable_object.builder.image_type_form_builder')] + FormBuilderInterface $formBuilder, + #[Autowire(service: 'prestashop.core.form.identifiable_object.handler.image_type_form_handler')] + FormHandlerInterface $formHandler, + ): Response { try { /** @var EditableImageType $editableImageType */ - $editableImageType = $this->getQueryBus()->handle(new GetImageTypeForEditing($imageTypeId)); - - $formBuilder = $this->get('prestashop.core.form.identifiable_object.builder.image_type_form_builder'); - $formHandler = $this->get('prestashop.core.form.identifiable_object.handler.image_type_form_handler'); + $editableImageType = $this->dispatchQuery(new GetImageTypeForEditing($imageTypeId)); $form = $formBuilder->getFormFor($imageTypeId); $form->handleRequest($request); @@ -176,7 +192,7 @@ public function editAction(int $imageTypeId, Request $request): Response $result = $formHandler->handleFor($imageTypeId, $form); if ($result->isSubmitted() && $result->isValid()) { - $this->addFlash('success', $this->trans('Update successful', 'Admin.Notifications.Success')); + $this->addFlash('success', $this->trans('Update successful', [], 'Admin.Notifications.Success')); return $this->redirectToRoute('admin_image_settings_index'); } @@ -192,7 +208,7 @@ public function editAction(int $imageTypeId, Request $request): Response 'form' => $form->createView(), 'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')), 'enableSidebar' => true, - 'layoutTitle' => $this->trans('Edit: %value%', 'Admin.Actions', ['%value%' => $editableImageType->getName()]), + 'layoutTitle' => $this->trans('Edit: %value%', ['%value%' => $editableImageType->getName()], 'Admin.Actions'), ]); } @@ -212,12 +228,12 @@ public function deleteAction(Request $request, int $imageTypeId): RedirectRespon // If we need to delete images files too if ($deleteForm->get('delete_images_files_too')->getNormData()) { - $this->getCommandBus()->handle(new DeleteImagesFromTypeCommand($imageTypeId)); + $this->dispatchCommand(new DeleteImagesFromTypeCommand($imageTypeId)); } // Delete image type - $this->getCommandBus()->handle(new DeleteImageTypeCommand($imageTypeId)); - $this->addFlash('success', $this->trans('Successful deletion', 'Admin.Notifications.Success')); + $this->dispatchCommand(new DeleteImageTypeCommand($imageTypeId)); + $this->addFlash('success', $this->trans('Successful deletion', [], 'Admin.Notifications.Success')); } catch (Exception $e) { $this->addFlash('error', $e->getMessage()); } @@ -238,11 +254,11 @@ public function bulkDeleteAction(Request $request): RedirectResponse $ids = $this->getBulkIdsFromRequest($request); try { - $this->getCommandBus()->handle(new BulkDeleteImageTypeCommand($ids)); + $this->dispatchCommand(new BulkDeleteImageTypeCommand($ids)); $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 (Exception $e) { $this->addFlash('error', $e->getMessage()); @@ -279,12 +295,12 @@ public function regenerateThumbnailsAction(Request $request): RedirectResponse $regenThumbnailsForm = $this->createForm(RegenerateThumbnailsType::class); $regenThumbnailsForm->handleRequest($request); - $this->getCommandBus()->handle(new RegenerateThumbnailsCommand( + $this->dispatchCommand(new RegenerateThumbnailsCommand( $regenThumbnailsForm->get('image')->getData(), $regenThumbnailsForm->get('image-type')->getData(), $regenThumbnailsForm->get('erase-previous-images')->getData() )); - $this->addFlash('success', $this->trans('The thumbnails were successfully regenerated.', 'Admin.Notifications.Success')); + $this->addFlash('success', $this->trans('The thumbnails were successfully regenerated.', [], 'Admin.Notifications.Success')); } catch (Exception $e) { $this->addFlash('error', $e->getMessage()); } diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Design/MailThemeController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Design/MailThemeController.php index ff79544d88645..746cb21ccfd18 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Design/MailThemeController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Design/MailThemeController.php @@ -29,25 +29,28 @@ use Exception; use Mail; use PrestaShop\PrestaShop\Adapter\MailTemplate\MailPreviewVariablesBuilder; +use PrestaShop\PrestaShop\Adapter\MailTemplate\MailTemplateTwigRenderer; use PrestaShop\PrestaShop\Core\Domain\MailTemplate\Command\GenerateThemeMailTemplatesCommand; -use PrestaShop\PrestaShop\Core\Employee\ContextEmployeeProviderInterface; use PrestaShop\PrestaShop\Core\Exception\CoreException; use PrestaShop\PrestaShop\Core\Exception\FileNotFoundException; use PrestaShop\PrestaShop\Core\Exception\InvalidArgumentException; use PrestaShop\PrestaShop\Core\Form\FormHandlerInterface; use PrestaShop\PrestaShop\Core\Language\LanguageRepositoryInterface; +use PrestaShop\PrestaShop\Core\MailTemplate\FolderThemeCatalog; use PrestaShop\PrestaShop\Core\MailTemplate\Layout\LayoutInterface; use PrestaShop\PrestaShop\Core\MailTemplate\MailTemplateInterface; use PrestaShop\PrestaShop\Core\MailTemplate\MailTemplateRendererInterface; use PrestaShop\PrestaShop\Core\MailTemplate\ThemeCatalogInterface; use PrestaShop\PrestaShop\Core\MailTemplate\ThemeInterface; use PrestaShop\PrestaShop\Core\MailTemplate\Transformation\MailVariablesTransformation; -use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; +use PrestaShopBundle\Controller\Admin\PrestaShopAdminController; use PrestaShopBundle\Form\Admin\Improve\Design\MailTheme\GenerateMailsType; use PrestaShopBundle\Form\Admin\Improve\Design\MailTheme\TranslateMailsBodyType; use PrestaShopBundle\Security\Attribute\AdminSecurity; use PrestaShopBundle\Service\TranslationService; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\Form\Form; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -58,8 +61,18 @@ * * Accessible via "Design > Mail Theme" */ -class MailThemeController extends FrameworkBundleAdminController +class MailThemeController extends PrestaShopAdminController { + public static function getSubscribedServices(): array + { + return parent::getSubscribedServices() + [ + ThemeCatalogInterface::class => FolderThemeCatalog::class, + MailPreviewVariablesBuilder::class => MailPreviewVariablesBuilder::class, + LanguageRepositoryInterface::class => LanguageRepositoryInterface::class, + MailTemplateRendererInterface::class => MailTemplateTwigRenderer::class, + ]; + } + /** * Show mail theme settings and generation page. * @@ -68,21 +81,22 @@ class MailThemeController extends FrameworkBundleAdminController * @return Response */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller'))")] - public function indexAction(Request $request) - { + public function indexAction( + Request $request, + #[Autowire(service: 'prestashop.admin.mail_theme.form_handler')] + FormHandlerInterface $formHandler, + ): Response { $legacyController = $request->attributes->get('_legacy_controller'); $generateThemeMailsForm = $this->createForm(GenerateMailsType::class); $translateMailsBodyForm = $this->createForm(TranslateMailsBodyType::class); - /** @var ThemeCatalogInterface $themeCatalog */ - $themeCatalog = $this->get('prestashop.core.mail_template.theme_catalog'); - $mailThemes = $themeCatalog->listThemes(); + $mailThemes = $this->container->get(ThemeCatalogInterface::class)->listThemes(); return $this->render('@PrestaShop/Admin/Improve/Design/MailTheme/index.html.twig', [ 'layoutHeaderToolbarBtn' => [], - 'layoutTitle' => $this->trans('Email theme', 'Admin.Navigation.Menu'), + 'layoutTitle' => $this->trans('Email theme', [], 'Admin.Navigation.Menu'), 'enableSidebar' => true, 'help_link' => $this->generateSidebarLink($legacyController), - 'mailThemeConfigurationForm' => $this->getMailThemeFormHandler()->getForm()->createView(), + 'mailThemeConfigurationForm' => $formHandler->getForm()->createView(), 'generateMailsForm' => $generateThemeMailsForm->createView(), 'translateMailsBodyForm' => $translateMailsBodyForm->createView(), 'mailThemes' => $mailThemes, @@ -97,14 +111,14 @@ public function indexAction(Request $request) * @return Response */ #[AdminSecurity("is_granted('create', request.get('_legacy_controller'))")] - public function generateMailsAction(Request $request) + public function generateMailsAction(Request $request): Response { $generateThemeMailsForm = $this->createForm(GenerateMailsType::class); $generateThemeMailsForm->handleRequest($request); if ($generateThemeMailsForm->isSubmitted()) { if (!$generateThemeMailsForm->isValid()) { - $this->flashErrors($this->getFormErrorsForJS($generateThemeMailsForm)); + $this->addFlashFormErrors($generateThemeMailsForm); return $this->redirectToRoute('admin_mail_theme_index'); } @@ -131,19 +145,18 @@ public function generateMailsAction(Request $request) $modulesMailFolder ); - $commandBus = $this->getCommandBus(); - $commandBus->handle($generateCommand); + $this->dispatchCommand($generateCommand); if ($data['overwrite']) { $this->addFlash( 'success', $this->trans( 'Successfully overwrote email templates for theme %s with locale %s', - 'Admin.Notifications.Success', [ $data['mailTheme'], $data['language'], - ] + ], + 'Admin.Notifications.Success' ) ); } else { @@ -151,22 +164,23 @@ public function generateMailsAction(Request $request) 'success', $this->trans( 'Successfully generated email templates for theme %s with locale %s', - 'Admin.Notifications.Success', [ $data['mailTheme'], $data['language'], - ] + ], + 'Admin.Notifications.Success' ) ); } } catch (CoreException $e) { - $this->flashErrors([ + $this->addFlashErrors([ $this->trans( sprintf( 'Cannot generate email templates for theme %s with locale %s', $data['mailTheme'], $data['language'] ), + [], 'Admin.Notifications.Error' ), $e->getMessage(), @@ -187,16 +201,17 @@ public function generateMailsAction(Request $request) * @throws Exception */ #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))")] - public function saveConfigurationAction(Request $request) - { - /** @var FormHandlerInterface $formHandler */ - $formHandler = $this->getMailThemeFormHandler(); + public function saveConfigurationAction( + Request $request, + #[Autowire(service: 'prestashop.admin.mail_theme.form_handler')] + FormHandlerInterface $formHandler + ): Response { /** @var Form $form */ $form = $formHandler->getForm()->handleRequest($request); if ($form->isSubmitted()) { if (!$form->isValid()) { - $this->flashErrors($this->getFormErrorsForJS($form)); + $this->addFlashFormErrors($form); return $this->redirectToRoute('admin_mail_theme_index'); } @@ -207,11 +222,12 @@ public function saveConfigurationAction(Request $request) 'success', $this->trans( 'Email theme configuration saved successfully', + [], 'Admin.Notifications.Success' ) ); } else { - $this->flashErrors($errors); + $this->addFlashErrors($errors); } } @@ -229,18 +245,15 @@ public function saveConfigurationAction(Request $request) * @throws InvalidArgumentException */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller'))")] - public function previewThemeAction(Request $request, $theme) + public function previewThemeAction(Request $request, string $theme): Response { $legacyController = $request->attributes->get('_legacy_controller'); - /** @var ThemeCatalogInterface $themeCatalog */ - $themeCatalog = $this->get('prestashop.core.mail_template.theme_catalog'); - /** @var ThemeInterface $mailTheme */ - $mailTheme = $themeCatalog->getByName($theme); + $mailTheme = $this->container->get(ThemeCatalogInterface::class)->getByName($theme); return $this->render('@PrestaShop/Admin/Improve/Design/MailTheme/preview.html.twig', [ 'layoutHeaderToolbarBtn' => [], - 'layoutTitle' => $this->trans('Previewing theme %s', 'Admin.Navigation.Menu', [$mailTheme->getName()]), + 'layoutTitle' => $this->trans('Previewing theme %s', [$mailTheme->getName()], 'Admin.Navigation.Menu'), 'enableSidebar' => true, 'help_link' => $this->generateSidebarLink($legacyController), 'mailTheme' => $mailTheme, @@ -267,30 +280,26 @@ public function previewThemeAction(Request $request, $theme) * @throws InvalidArgumentException */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller'))")] - public function sendTestMailAction($theme, $layout, $locale, $module = '') + public function sendTestMailAction(string $theme, string $layout, string $locale, string $module = ''): Response { if ($this->getConfiguration()->get('PS_MAIL_THEME') !== $theme) { $this->addFlash( 'error', $this->trans( 'Cannot send test email for theme %theme% because it is not your current theme', - 'Admin.Notifications.Error', [ '%theme%' => $theme, - ] + ], + 'Admin.Notifications.Error' ) ); return $this->redirectToRoute('admin_mail_theme_preview', ['theme' => $theme]); } - /** @var ContextEmployeeProviderInterface $employeeProvider */ - $employeeProvider = $this->get('prestashop.adapter.data_provider.employee'); - $employeeData = $employeeProvider->getData(); + $employeeData = $this->getEmployeeContext()->getEmployee(); - /** @var LanguageRepositoryInterface $languageRepository */ - $languageRepository = $this->get('prestashop.core.admin.lang.repository'); - $language = $languageRepository->getOneByLocaleOrIsoCode($locale); + $language = $this->container->get(LanguageRepositoryInterface::class)->getOneByLocaleOrIsoCode($locale); if (null === $language) { throw new InvalidArgumentException(sprintf('Cannot find Language with locale or isoCode %s', $locale)); } @@ -301,20 +310,18 @@ public function sendTestMailAction($theme, $layout, $locale, $module = '') $templatePath = _PS_MODULE_DIR_ . $module . '/mails/'; } - /** @var MailPreviewVariablesBuilder $variablesBuilder */ - $variablesBuilder = $this->get('prestashop.adapter.mail_template.preview_variables_builder'); $mailLayout = $this->getMailLayout($theme, $layout, $module); - $mailVariables = $variablesBuilder->buildTemplateVariables($mailLayout); + $mailVariables = $this->container->get(MailPreviewVariablesBuilder::class)->buildTemplateVariables($mailLayout); $mailSent = Mail::send( $language->getId(), $layout, - $this->trans('Test email %template%', 'Admin.Design.Feature', ['%template%' => $layout]), + $this->trans('Test email %template%', ['%template%' => $layout], 'Admin.Design.Feature'), $mailVariables, - $employeeData['email'], - $employeeData['firstname'] . ' ' . $employeeData['lastname'], - $employeeData['email'], - $employeeData['firstname'] . ' ' . $employeeData['lastname'], + $employeeData->getEmail(), + $employeeData->getFirstName() . ' ' . $employeeData->getLastName(), + $employeeData->getEmail(), + $employeeData->getFirstName() . ' ' . $employeeData->getLastName(), null, null, $templatePath @@ -325,11 +332,11 @@ public function sendTestMailAction($theme, $layout, $locale, $module = '') 'success', $this->trans( 'Test email for layout %layout% was successfully sent to %email%', - 'Admin.Notifications.Success', [ '%layout%' => $layout, - '%email%' => $employeeData['email'], - ] + '%email%' => $employeeData->getEmail(), + ], + 'Admin.Notifications.Success' ) ); } else { @@ -337,10 +344,10 @@ public function sendTestMailAction($theme, $layout, $locale, $module = '') 'error', $this->trans( 'Cannot send test email for layout %layout%', - 'Admin.Notifications.Error', [ '%layout%' => $layout, - ] + ], + 'Admin.Notifications.Error' ) ); } @@ -351,11 +358,14 @@ public function sendTestMailAction($theme, $layout, $locale, $module = '') /** * @param Request $request * - * @return \Symfony\Component\HttpFoundation\RedirectResponse + * @return RedirectResponse */ #[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", message: 'You do not have permission to update this.')] - public function translateBodyAction(Request $request) - { + public function translateBodyAction( + Request $request, + #[Autowire(service: 'prestashop.service.translation')] + TranslationService $translationService + ): RedirectResponse { $translateMailsBodyForm = $this->createForm(TranslateMailsBodyType::class); $translateMailsBodyForm->handleRequest($request); @@ -364,6 +374,7 @@ public function translateBodyAction(Request $request) 'error', $this->trans( 'Cannot translate emails body content', + [], 'Admin.Notifications.Error' ) ); @@ -373,8 +384,6 @@ public function translateBodyAction(Request $request) $translateData = $translateMailsBodyForm->getData(); $language = $translateData['language']; - /** @var TranslationService $translationService */ - $translationService = $this->get('prestashop.service.translation'); $locale = $translationService->langToLocale($language); return $this->redirectToRoute('admin_international_translation_overview', [ @@ -399,7 +408,7 @@ public function translateBodyAction(Request $request) * @throws InvalidArgumentException */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller'))")] - public function previewLayoutAction($theme, $layout, $type, $locale, $module = '') + public function previewLayoutAction(string $theme, string $layout, string $type, string $locale, string $module = ''): Response { $renderedLayout = $this->renderLayout($theme, $layout, $type, $locale, $module); @@ -421,7 +430,7 @@ public function previewLayoutAction($theme, $layout, $type, $locale, $module = ' * @throws InvalidArgumentException */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller'))")] - public function rawLayoutAction($theme, $layout, $type, $locale, $module = '') + public function rawLayoutAction(string $theme, string $layout, string $type, string $locale, string $module = ''): Response { $renderedLayout = $this->renderLayout($theme, $layout, $type, $locale, $module); @@ -447,26 +456,21 @@ public function rawLayoutAction($theme, $layout, $type, $locale, $module = '') * @throws FileNotFoundException * @throws InvalidArgumentException */ - private function renderLayout($themeName, $layoutName, $type, $locale = '', $module = '') + private function renderLayout(string $themeName, string $layoutName, string $type, string $locale = '', string $module = ''): string { $layout = $this->getMailLayout($themeName, $layoutName, $module); - /** @var LanguageRepositoryInterface $languageRepository */ - $languageRepository = $this->get('prestashop.core.admin.lang.repository'); if (empty($locale)) { - $locale = $this->getContext()->language->locale; + $locale = $this->getLanguageContext()->getLocale(); } - $language = $languageRepository->getOneByLocaleOrIsoCode($locale); + $language = $this->container->get(LanguageRepositoryInterface::class)->getOneByLocaleOrIsoCode($locale); if (null === $language) { throw new InvalidArgumentException(sprintf('Cannot find Language with locale or isoCode %s', $locale)); } - /** @var MailPreviewVariablesBuilder $variablesBuilder */ - $variablesBuilder = $this->get('prestashop.adapter.mail_template.preview_variables_builder'); - $mailLayoutVariables = $variablesBuilder->buildTemplateVariables($layout); + $mailLayoutVariables = $this->container->get(MailPreviewVariablesBuilder::class)->buildTemplateVariables($layout); - /** @var MailTemplateRendererInterface $renderer */ - $renderer = $this->get('prestashop.core.mail_template.mail_template_renderer'); + $renderer = $this->container->get(MailTemplateRendererInterface::class); // Special case for preview, we fill the mail variables $renderer->addTransformation(new MailVariablesTransformation(MailTemplateInterface::HTML_TYPE, $mailLayoutVariables)); $renderer->addTransformation(new MailVariablesTransformation(MailTemplateInterface::TXT_TYPE, $mailLayoutVariables)); @@ -495,10 +499,9 @@ private function renderLayout($themeName, $layoutName, $type, $locale = '', $mod * @throws FileNotFoundException * @throws InvalidArgumentException */ - private function getMailLayout($themeName, $layoutName, $module) + private function getMailLayout(string $themeName, string $layoutName, string $module): LayoutInterface { - /** @var ThemeCatalogInterface $themeCatalog */ - $themeCatalog = $this->get('prestashop.core.mail_template.theme_catalog'); + $themeCatalog = $this->container->get(ThemeCatalogInterface::class); /** @var ThemeInterface $theme */ $theme = $themeCatalog->getByName($themeName); @@ -520,12 +523,4 @@ private function getMailLayout($themeName, $layoutName, $module) return $layout; } - - /** - * @return FormHandlerInterface - */ - private function getMailThemeFormHandler(): FormHandlerInterface - { - return $this->get('prestashop.admin.mail_theme.form_handler'); - } } diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Design/PositionsController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Design/PositionsController.php index c1428032cdac9..12301a24e910c 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Design/PositionsController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Design/PositionsController.php @@ -27,13 +27,21 @@ namespace PrestaShopBundle\Controller\Admin\Improve\Design; use Hook; +use Module as LegacyModule; +use PrestaShop\PrestaShop\Adapter\Hook\HookInformationProvider; +use PrestaShop\PrestaShop\Adapter\LegacyContext; +use PrestaShop\PrestaShop\Adapter\Module\Module; +use PrestaShop\PrestaShop\Adapter\Validate; use PrestaShop\PrestaShop\Core\Domain\Hook\Command\UpdateHookStatusCommand; use PrestaShop\PrestaShop\Core\Domain\Hook\Exception\HookException; use PrestaShop\PrestaShop\Core\Domain\Hook\Exception\HookNotFoundException; use PrestaShop\PrestaShop\Core\Domain\Hook\Exception\HookUpdateHookException; use PrestaShop\PrestaShop\Core\Domain\Hook\Query\GetHookStatus; -use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; +use PrestaShop\PrestaShop\Core\Domain\Hook\QueryResult\HookStatus; +use PrestaShop\PrestaShop\Core\Shop\ShopContextInterface; +use PrestaShopBundle\Controller\Admin\PrestaShopAdminController; use PrestaShopBundle\Security\Attribute\AdminSecurity; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -41,7 +49,7 @@ /** * Configuration modules positions "Improve > Design > Positions". */ -class PositionsController extends FrameworkBundleAdminController +class PositionsController extends PrestaShopAdminController { /** * @var int @@ -56,17 +64,21 @@ class PositionsController extends FrameworkBundleAdminController * @return Response */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller')) || is_granted('update', request.get('_legacy_controller')) || is_granted('create', request.get('_legacy_controller')) || is_granted('delete', request.get('_legacy_controller'))", message: 'Access denied.')] - public function indexAction(Request $request): Response - { - $isSingleShopContext = $this->get('prestashop.adapter.shop.context')->isSingleShopContext(); + public function indexAction( + Request $request, + #[Autowire(service: 'prestashop.adapter.legacy.module')] + Module $moduleAdapter, + #[Autowire(service: 'prestashop.adapter.legacy.hook')] + HookInformationProvider $hookProvider, + LegacyContext $legacyContextService + ): Response { + $isSingleShopContext = $this->getShopContext()->getShopConstraint()->isSingleShopContext(); if (!$isSingleShopContext) { return $this->render('@PrestaShop/Admin/Improve/Design/positions.html.twig', [ 'isSingleShopContext' => $isSingleShopContext, ]); } - $moduleAdapter = $this->get('prestashop.adapter.legacy.module'); - $hookProvider = $this->get('prestashop.adapter.legacy.hook'); $installedModules = $moduleAdapter->getModulesInstalled(); $selectedModule = $request->get('show_modules'); @@ -78,7 +90,9 @@ public function indexAction(Request $request): Response $modules = []; foreach ($installedModules as $installedModule) { - if ($module = $moduleAdapter->getInstanceById($installedModule['id_module'])) { + /** @var LegacyModule|false $module */ + $module = $moduleAdapter->getInstanceById($installedModule['id_module']); + if ($module) { // We want to be able to sort modules by display name $modules[(int) $module->id] = $module; } @@ -113,7 +127,6 @@ public function indexAction(Request $request): Response $hooks[$key]['position'] = $hookProvider->isDisplayHookName($hook['name']); } - $legacyContextService = $this->get('prestashop.adapter.legacy.context'); $saveUrlParams = [ 'addToHook' => '', ]; @@ -127,12 +140,12 @@ public function indexAction(Request $request): Response 'save' => [ 'class' => 'btn-primary transplant-module-button', 'href' => $saveUrl, - 'desc' => $this->trans('Hook a module', 'Admin.Design.Feature'), + 'desc' => $this->trans('Hook a module', [], 'Admin.Design.Feature'), 'icon' => 'anchor', ], ], 'selectedModule' => $this->selectedModule, - 'layoutTitle' => $this->trans('Module positions', 'Admin.Navigation.Menu'), + 'layoutTitle' => $this->trans('Module positions', [], 'Admin.Navigation.Menu'), 'requireBulkActions' => false, 'requireFilterStatus' => false, 'showContentHeader' => true, @@ -152,16 +165,21 @@ public function indexAction(Request $request): Response * @return Response */ #[AdminSecurity("is_granted('delete', request.get('_legacy_controller')~'_')", message: 'Access denied.')] - public function unhookAction(Request $request) - { - $validateAdapter = $this->get('prestashop.adapter.validate'); + public function unhookAction( + Request $request, + #[Autowire(service: 'prestashop.adapter.legacy.module')] + Module $moduleAdapter, + #[Autowire(service: 'prestashop.adapter.validate')] + Validate $validateAdapter, + ShopContextInterface $shopContext + ): Response { $unhooks = $request->request->all('unhooks'); $context = null; if (empty($unhooks)) { $moduleId = $request->query->get('moduleId'); $hookId = $request->query->get('hookId'); $unhooks = [sprintf('%d_%d', $hookId, $moduleId)]; - $context = $this->get('prestashop.adapter.shop.context')->getContextListShopID(); + $context = $shopContext->getContextShopIds(); } $errors = []; @@ -169,12 +187,14 @@ public function unhookAction(Request $request) $explode = explode('_', $unhook); $hookId = (int) isset($explode[0]) ? $explode[0] : 0; $moduleId = (int) isset($explode[1]) ? $explode[1] : 0; - $module = $this->get('prestashop.adapter.legacy.module')->getInstanceById($moduleId); + /** @var LegacyModule|false $module */ + $module = $moduleAdapter->getInstanceById($moduleId); $hook = new Hook($hookId); if (!$module) { $errors[] = $this->trans( 'This module cannot be loaded.', + [], 'Admin.Modules.Notification' ); @@ -184,6 +204,7 @@ public function unhookAction(Request $request) if (!$validateAdapter->isLoadedObject($hook)) { $errors[] = $this->trans( 'Hook cannot be loaded.', + [], 'Admin.Modules.Notification' ); @@ -193,18 +214,20 @@ public function unhookAction(Request $request) if (!$module->unregisterHook($hookId, $context) || !$module->unregisterExceptions($hookId, $context)) { $errors[] = $this->trans( 'An error occurred while deleting the module from its hook.', + [], 'Admin.Modules.Notification' ); } } if (!empty($errors)) { - $this->flashErrors($errors); + $this->addFlashErrors($errors); } else { $this->addFlash( 'success', $this->trans( 'The module was successfully removed from the hook.', + [], 'Admin.Modules.Notification' ) ); @@ -228,8 +251,8 @@ private function manageLegacyFlashes($messageId) } $messages = [ - 16 => $this->trans('The module transplanted successfully to the hook.', 'Admin.Modules.Notification'), - 17 => $this->trans('The module was successfully removed from the hook.', 'Admin.Modules.Notification'), + 16 => $this->trans('The module transplanted successfully to the hook.', [], 'Admin.Modules.Notification'), + 17 => $this->trans('The module was successfully removed from the hook.', [], 'Admin.Modules.Notification'), ]; if (isset($messages[$messageId])) { @@ -254,11 +277,12 @@ public function toggleStatusAction(Request $request) $hookStatus = false; try { - $hookStatus = !$this->getQueryBus()->handle(new GetHookStatus($hookId)); - $this->getCommandBus()->handle(new UpdateHookStatusCommand($hookId, (bool) $hookStatus)); + /** @var HookStatus $hookStatus */ + $hookStatus = $this->dispatchQuery(new GetHookStatus($hookId)); + $this->dispatchCommand(new UpdateHookStatusCommand($hookId, !$hookStatus->isActive())); $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 (HookException $e) { $response = [ @@ -278,8 +302,8 @@ public function toggleStatusAction(Request $request) private function getErrorMessages(): array { return [ - HookNotFoundException::class => $this->trans('The object cannot be loaded (or found).', 'Admin.Notifications.Error'), - HookUpdateHookException::class => $this->trans('An error occurred while updating the status for an object.', 'Admin.Notifications.Error'), + HookNotFoundException::class => $this->trans('The object cannot be loaded (or found).', [], 'Admin.Notifications.Error'), + HookUpdateHookException::class => $this->trans('An error occurred while updating the status for an object.', [], 'Admin.Notifications.Error'), ]; } } diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Payment/PaymentMethodsController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Payment/PaymentMethodsController.php index 6f65b8e27c06d..23e224c1c074f 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Payment/PaymentMethodsController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Payment/PaymentMethodsController.php @@ -26,7 +26,8 @@ namespace PrestaShopBundle\Controller\Admin\Improve\Payment; -use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; +use PrestaShop\PrestaShop\Adapter\Presenter\Module\PaymentModulesPresenter; +use PrestaShopBundle\Controller\Admin\PrestaShopAdminController; use PrestaShopBundle\Security\Attribute\AdminSecurity; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -34,7 +35,7 @@ /** * Class PaymentMethodsController is responsible for 'Improve > Payment > Payment Methods' page. */ -class PaymentMethodsController extends FrameworkBundleAdminController +class PaymentMethodsController extends PrestaShopAdminController { /** * Show payment method modules. @@ -44,23 +45,23 @@ class PaymentMethodsController extends FrameworkBundleAdminController * @return Response */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller'))")] - public function indexAction(Request $request) - { + public function indexAction( + Request $request, + PaymentModulesPresenter $paymentMethodsPresenter + ): Response { $legacyController = $request->attributes->get('_legacy_controller'); - $shopContext = $this->get('prestashop.adapter.shop.context'); - $isSingleShopContext = $shopContext->isSingleShopContext(); + $isSingleShopContext = $this->getShopContext()->getShopConstraint()->isSingleShopContext(); $paymentModules = []; if ($isSingleShopContext) { - $paymentMethodsPresenter = $this->get('prestashop.adapter.presenter.module.payment'); $paymentModules = $paymentMethodsPresenter->present(); } return $this->render('@PrestaShop/Admin/Improve/Payment/PaymentMethods/payment_methods.html.twig', [ 'paymentModules' => $paymentModules, 'isSingleShopContext' => $isSingleShopContext, - 'layoutTitle' => $this->trans('Payment methods', 'Admin.Navigation.Menu'), + 'layoutTitle' => $this->trans('Payment methods', [], 'Admin.Navigation.Menu'), 'enableSidebar' => true, 'help_link' => $this->generateSidebarLink($legacyController), ]); diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Payment/PaymentPreferencesController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Payment/PaymentPreferencesController.php index a3ee378e272d8..c0ec32073ac25 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Payment/PaymentPreferencesController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Payment/PaymentPreferencesController.php @@ -27,8 +27,10 @@ namespace PrestaShopBundle\Controller\Admin\Improve\Payment; use PrestaShop\PrestaShop\Core\Form\FormHandlerInterface; -use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; +use PrestaShop\PrestaShop\Core\Module\DataProvider\PaymentModuleListProviderInterface; +use PrestaShopBundle\Controller\Admin\PrestaShopAdminController; use PrestaShopBundle\Security\Attribute\AdminSecurity; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -36,7 +38,7 @@ /** * Class PaymentPreferencesController is responsible for "Improve > Payment > Preferences" page. */ -class PaymentPreferencesController extends FrameworkBundleAdminController +class PaymentPreferencesController extends PrestaShopAdminController { /** * Show payment preferences page. @@ -46,21 +48,23 @@ class PaymentPreferencesController extends FrameworkBundleAdminController * @return Response */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller'))", message: 'Access denied.')] - public function indexAction(Request $request) - { + public function indexAction( + Request $request, + #[Autowire(service: 'prestashop.admin.payment_preferences.form_handler')] + FormHandlerInterface $paymentPreferencesFormHandler, + #[Autowire(service: 'prestashop.adapter.module.payment_module_provider')] + PaymentModuleListProviderInterface $paymentModulesListProvider + ): Response { $legacyController = $request->attributes->get('_legacy_controller'); - $paymentModulesListProvider = $this->get('prestashop.adapter.module.payment_module_provider'); - $shopContext = $this->get('prestashop.adapter.shop.context'); - - $isSingleShopContext = $shopContext->isSingleShopContext(); + $isSingleShopContext = $this->getShopContext()->getShopConstraint()->isSingleShopContext(); $paymentPreferencesForm = null; $paymentModulesCount = 0; if ($isSingleShopContext) { $paymentModulesCount = count($paymentModulesListProvider->getPaymentModuleList()); - $paymentPreferencesForm = $this->getPaymentPreferencesFormHandler()->getForm()->createView(); + $paymentPreferencesForm = $paymentPreferencesFormHandler->getForm()->createView(); } return $this->render('@PrestaShop/Admin/Improve/Payment/Preferences/payment_preferences.html.twig', [ @@ -69,7 +73,7 @@ public function indexAction(Request $request) 'paymentPreferencesForm' => $paymentPreferencesForm, 'isSingleShopContext' => $isSingleShopContext, 'paymentModulesCount' => $paymentModulesCount, - 'layoutTitle' => $this->trans('Preferences', 'Admin.Navigation.Menu'), + 'layoutTitle' => $this->trans('Preferences', [], 'Admin.Navigation.Menu'), ]); } @@ -81,10 +85,11 @@ public function indexAction(Request $request) * @return RedirectResponse */ #[AdminSecurity("is_granted('update', request.get('_legacy_controller')) && is_granted('create', request.get('_legacy_controller')) && is_granted('delete', request.get('_legacy_controller'))", message: 'Access denied.', redirectRoute: 'admin_payment_preferences')] - public function processFormAction(Request $request) - { - $paymentPreferencesFormHandler = $this->getPaymentPreferencesFormHandler(); - + public function processFormAction( + Request $request, + #[Autowire(service: 'prestashop.admin.payment_preferences.form_handler')] + FormHandlerInterface $paymentPreferencesFormHandler + ): RedirectResponse { $paymentPreferencesForm = $paymentPreferencesFormHandler->getForm(); $paymentPreferencesForm->handleRequest($request); @@ -93,22 +98,14 @@ public function processFormAction(Request $request) $errors = $paymentPreferencesFormHandler->save($paymentPreferences); if (empty($errors)) { - $this->addFlash('success', $this->trans('Successful update', 'Admin.Notifications.Success')); + $this->addFlash('success', $this->trans('Successful update', [], 'Admin.Notifications.Success')); return $this->redirectToRoute('admin_payment_preferences'); } - $this->flashErrors($errors); + $this->addFlashErrors($errors); } return $this->redirectToRoute('admin_payment_preferences'); } - - /** - * @return FormHandlerInterface - */ - private function getPaymentPreferencesFormHandler(): FormHandlerInterface - { - return $this->get('prestashop.admin.payment_preferences.form_handler'); - } } diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Shipping/PreferencesController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Shipping/PreferencesController.php index 01daf9cffa96b..a156f96eca7e5 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Shipping/PreferencesController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Shipping/PreferencesController.php @@ -27,8 +27,9 @@ namespace PrestaShopBundle\Controller\Admin\Improve\Shipping; use PrestaShop\PrestaShop\Core\Form\FormHandlerInterface; -use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; +use PrestaShopBundle\Controller\Admin\PrestaShopAdminController; use PrestaShopBundle\Security\Attribute\AdminSecurity; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -36,7 +37,7 @@ /** * Controller responsible for "Improve > Shipping > Preferences" page. */ -class PreferencesController extends FrameworkBundleAdminController +class PreferencesController extends PrestaShopAdminController { /** * Show shipping preferences page. @@ -46,10 +47,15 @@ class PreferencesController extends FrameworkBundleAdminController * @return Response */ #[AdminSecurity("is_granted('read', request.get('_legacy_controller'))")] - public function indexAction(Request $request) - { - $handlingForm = $this->getHandlingFormHandler()->getForm(); - $carrierOptionsForm = $this->getCarrierOptionsFormHandler()->getForm(); + public function indexAction( + Request $request, + #[Autowire(service: 'prestashop.admin.shipping_preferences.handling.form_handler')] + FormHandlerInterface $handlingFormHandler, + #[Autowire(service: 'prestashop.admin.shipping_preferences.carrier_options.form_handler')] + FormHandlerInterface $carrierOptionsFormHandler + ): Response { + $handlingForm = $handlingFormHandler->getForm(); + $carrierOptionsForm = $carrierOptionsFormHandler->getForm(); return $this->doRenderForm($handlingForm, $carrierOptionsForm, $request); } @@ -60,32 +66,39 @@ public function indexAction(Request $request) * @return Response */ #[AdminSecurity("is_granted('update', request.get('_legacy_controller')) && is_granted('create', request.get('_legacy_controller')) && is_granted('delete', request.get('_legacy_controller'))", message: 'You do not have permission to edit this.', redirectRoute: 'admin_shipping_preferences')] - public function processCarrierOptionsFormAction(Request $request) - { - $formHandler = $this->getCarrierOptionsFormHandler(); - $this->dispatchHook( + public function processCarrierOptionsFormAction( + Request $request, + #[Autowire(service: 'prestashop.admin.shipping_preferences.handling.form_handler')] + FormHandlerInterface $handlingFormHandler, + #[Autowire(service: 'prestashop.admin.shipping_preferences.carrier_options.form_handler')] + FormHandlerInterface $carrierOptionsFormHandler + ): Response { + $this->dispatchHookWithParameters( 'actionAdminShippingPreferencesControllerPostProcessCarrierOptionsBefore', ['controller' => $this] ); - $this->dispatchHook('actionAdminShippingPreferencesControllerPostProcessBefore', ['controller' => $this]); + $this->dispatchHookWithParameters( + 'actionAdminShippingPreferencesControllerPostProcessBefore', + ['controller' => $this] + ); - $form = $formHandler->getForm(); + $form = $carrierOptionsFormHandler->getForm(); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $data = $form->getData(); - $saveErrors = $formHandler->save($data); + $saveErrors = $carrierOptionsFormHandler->save($data); if (0 === count($saveErrors)) { - $this->addFlash('success', $this->trans('Update successful', 'Admin.Notifications.Success')); + $this->addFlash('success', $this->trans('Update successful', [], 'Admin.Notifications.Success')); return $this->redirectToRoute('admin_shipping_preferences'); } - $this->flashErrors($saveErrors); + $this->addFlashErrors($saveErrors); } - return $this->doRenderForm($this->getHandlingFormHandler()->getForm(), $form, $request); + return $this->doRenderForm($handlingFormHandler->getForm(), $form, $request); } /** @@ -94,47 +107,38 @@ public function processCarrierOptionsFormAction(Request $request) * @return Response */ #[AdminSecurity("is_granted('update', request.get('_legacy_controller')) && is_granted('create', request.get('_legacy_controller')) && is_granted('delete', request.get('_legacy_controller'))", message: 'You do not have permission to edit this.', redirectRoute: 'admin_shipping_preferences')] - public function processHandlingFormAction(Request $request) - { - $formHandler = $this->getHandlingFormHandler(); - $this->dispatchHook( + public function processHandlingFormAction( + Request $request, + #[Autowire(service: 'prestashop.admin.shipping_preferences.handling.form_handler')] + FormHandlerInterface $handlingFormHandler, + #[Autowire(service: 'prestashop.admin.shipping_preferences.carrier_options.form_handler')] + FormHandlerInterface $carrierOptionsFormHandler + ): Response { + $this->dispatchHookWithParameters( 'actionAdminShippingPreferencesControllerPostProcessHandlingBefore', ['controller' => $this] ); - $this->dispatchHook('actionAdminShippingPreferencesControllerPostProcessBefore', ['controller' => $this]); + $this->dispatchHookWithParameters( + 'actionAdminShippingPreferencesControllerPostProcessBefore', + ['controller' => $this] + ); - $form = $formHandler->getForm(); + $form = $handlingFormHandler->getForm(); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $data = $form->getData(); - $saveErrors = $formHandler->save($data); + $saveErrors = $handlingFormHandler->save($data); if (0 === count($saveErrors)) { - $this->addFlash('success', $this->trans('Update successful', 'Admin.Notifications.Success')); + $this->addFlash('success', $this->trans('Update successful', [], 'Admin.Notifications.Success')); return $this->redirectToRoute('admin_shipping_preferences'); } } - return $this->doRenderForm($form, $this->getCarrierOptionsFormHandler()->getForm(), $request); - } - - /** - * @return FormHandlerInterface - */ - protected function getHandlingFormHandler(): FormHandlerInterface - { - return $this->get('prestashop.admin.shipping_preferences.handling.form_handler'); - } - - /** - * @return FormHandlerInterface - */ - protected function getCarrierOptionsFormHandler(): FormHandlerInterface - { - return $this->get('prestashop.admin.shipping_preferences.carrier_options.form_handler'); + return $this->doRenderForm($form, $carrierOptionsFormHandler->getForm(), $request); } /** @@ -149,7 +153,7 @@ private function doRenderForm($handlingForm, $carrierOptionsForm, $request): Res $legacyController = $request->attributes->get('_legacy_controller'); return $this->render('@PrestaShop/Admin/Improve/Shipping/Preferences/preferences.html.twig', [ - 'layoutTitle' => $this->trans('Preferences', 'Admin.Navigation.Menu'), + 'layoutTitle' => $this->trans('Preferences', [], 'Admin.Navigation.Menu'), 'enableSidebar' => true, 'help_link' => $this->generateSidebarLink($legacyController), 'handlingForm' => $handlingForm->createView(), diff --git a/src/PrestaShopBundle/Resources/config/services/adapter/mail_template.yml b/src/PrestaShopBundle/Resources/config/services/adapter/mail_template.yml index 0345df6c72be9..4ffc1477ff659 100644 --- a/src/PrestaShopBundle/Resources/config/services/adapter/mail_template.yml +++ b/src/PrestaShopBundle/Resources/config/services/adapter/mail_template.yml @@ -2,8 +2,7 @@ services: _defaults: public: true - prestashop.adapter.mail_template.twig_renderer: - class: 'PrestaShop\PrestaShop\Adapter\MailTemplate\MailTemplateTwigRenderer' + PrestaShop\PrestaShop\Adapter\MailTemplate\MailTemplateTwigRenderer: arguments: - '@twig' - '@prestashop.core.mail_template.variables_builder' @@ -17,13 +16,18 @@ services: arguments: - '@prestashop.core.mail_template.transformation.html_textify' + prestashop.adapter.mail_template.twig_renderer: + alias: 'PrestaShop\PrestaShop\Adapter\MailTemplate\MailTemplateTwigRenderer' + deprecated: + package: PrestaShop\PrestaShop + version: 9.0 + prestashop.adapter.mail_template.partial_template_renderer: class: 'PrestaShop\PrestaShop\Adapter\MailTemplate\MailPartialTemplateRenderer' arguments: - "@=service('prestashop.adapter.legacy.context').getSmarty()" - prestashop.adapter.mail_template.preview_variables_builder: - class: 'PrestaShop\PrestaShop\Adapter\MailTemplate\MailPreviewVariablesBuilder' + PrestaShop\PrestaShop\Adapter\MailTemplate\MailPreviewVariablesBuilder: arguments: - '@prestashop.adapter.legacy.configuration' - '@prestashop.adapter.legacy.context' @@ -31,3 +35,9 @@ services: - "@prestashop.adapter.mail_template.partial_template_renderer" - "@prestashop.core.localization.locale.context_locale" - "@translator" + + prestashop.adapter.mail_template.preview_variables_builder: + alias: 'PrestaShop\PrestaShop\Adapter\MailTemplate\MailPreviewVariablesBuilder' + deprecated: + package: PrestaShop\PrestaShop + version: 9.0 diff --git a/src/PrestaShopBundle/Resources/config/services/adapter/module.yml b/src/PrestaShopBundle/Resources/config/services/adapter/module.yml index 3f0cc567cfb1d..2d329f9fd4173 100644 --- a/src/PrestaShopBundle/Resources/config/services/adapter/module.yml +++ b/src/PrestaShopBundle/Resources/config/services/adapter/module.yml @@ -68,12 +68,17 @@ services: version: 9.0 public: true - prestashop.adapter.presenter.module.payment: - class: PrestaShop\PrestaShop\Adapter\Presenter\Module\PaymentModulesPresenter + PrestaShop\PrestaShop\Adapter\Presenter\Module\PaymentModulesPresenter: arguments: - '@prestashop.adapter.presenter.module' - '@prestashop.adapter.module.payment_module_provider' + prestashop.adapter.presenter.module.payment: + alias: PrestaShop\PrestaShop\Adapter\Presenter\Module\PaymentModulesPresenter + deprecated: + package: PrestaShop\PrestaShop + version: 9.0 + prestashop.adapter.module.payment_module_provider: class: PrestaShop\PrestaShop\Adapter\Module\PaymentModuleListProvider arguments: 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 a3efc2937c624..1cd214dc667ab 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 @@ -131,8 +131,7 @@ services: parent: PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory public: true - prestashop.core.grid.definition.factory.cms_page_category: - class: 'PrestaShop\PrestaShop\Core\Grid\Definition\Factory\CmsPageCategoryDefinitionFactory' + PrestaShop\PrestaShop\Core\Grid\Definition\Factory\CmsPageCategoryDefinitionFactory: parent: PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory arguments: - '@request_stack' @@ -140,6 +139,12 @@ services: - '@=service("prestashop.adapter.multistore_feature").isUsed()' public: true + prestashop.core.grid.definition.factory.cms_page_category: + alias: 'PrestaShop\PrestaShop\Core\Grid\Definition\Factory\CmsPageCategoryDefinitionFactory' + deprecated: + package: PrestaShop\PrestaShop + version: 9.0 + prestashop.core.grid.definition.factory.tax: class: 'PrestaShop\PrestaShop\Core\Grid\Definition\Factory\TaxGridDefinitionFactory' parent: PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory @@ -155,8 +160,7 @@ services: parent: PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory public: true - prestashop.core.grid.definition.factory.cms_page: - class: 'PrestaShop\PrestaShop\Core\Grid\Definition\Factory\CmsPageDefinitionFactory' + PrestaShop\PrestaShop\Core\Grid\Definition\Factory\CmsPageDefinitionFactory: parent: PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory arguments: - '@prestashop.core.query_bus' @@ -165,6 +169,12 @@ services: - '@=service("prestashop.adapter.multistore_feature").isUsed()' public: true + prestashop.core.grid.definition.factory.cms_page: + alias: 'PrestaShop\PrestaShop\Core\Grid\Definition\Factory\CmsPageDefinitionFactory' + deprecated: + package: PrestaShop\PrestaShop + version: 9.0 + PrestaShop\PrestaShop\Core\Grid\Definition\Factory\Monitoring\EmptyCategoryGridDefinitionFactory: parent: PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory arguments: diff --git a/src/PrestaShopBundle/Resources/config/services/core/mail_template.yml b/src/PrestaShopBundle/Resources/config/services/core/mail_template.yml index f2e56baa7728c..2fdefcf67535e 100644 --- a/src/PrestaShopBundle/Resources/config/services/core/mail_template.yml +++ b/src/PrestaShopBundle/Resources/config/services/core/mail_template.yml @@ -8,13 +8,18 @@ services: prestashop.core.mail_template.theme_folder_scanner: class: 'PrestaShop\PrestaShop\Core\MailTemplate\FolderThemeScanner' - prestashop.core.mail_template.theme_folder_catalog: - class: 'PrestaShop\PrestaShop\Core\MailTemplate\FolderThemeCatalog' + PrestaShop\PrestaShop\Core\MailTemplate\FolderThemeCatalog: arguments: - '%mail_themes_dir%' - '@prestashop.core.mail_template.theme_folder_scanner' - '@prestashop.core.hook.dispatcher' + prestashop.core.mail_template.theme_folder_catalog: + alias: 'PrestaShop\PrestaShop\Core\MailTemplate\FolderThemeCatalog' + deprecated: + package: PrestaShop\PrestaShop + version: 9.0 + prestashop.core.mail_template.variables_builder: class: 'PrestaShop\PrestaShop\Core\MailTemplate\Layout\LayoutVariablesBuilder' arguments: