diff --git a/app/src/Controller/Admin/BlogArticleController.php b/app/src/Controller/Admin/BlogArticleController.php index 0e4dd8e41e..582f966d9f 100644 --- a/app/src/Controller/Admin/BlogArticleController.php +++ b/app/src/Controller/Admin/BlogArticleController.php @@ -9,78 +9,49 @@ use App\Model\Blog\Article\BlogArticleFacade; use App\Model\Blog\Article\BlogArticleGridFactory; use Shopsys\FrameworkBundle\Component\ConfirmDelete\ConfirmDeleteResponseFactory; -use Shopsys\FrameworkBundle\Component\Domain\AdminDomainTabsFacade; -use Shopsys\FrameworkBundle\Component\Domain\Domain; -use Shopsys\FrameworkBundle\Component\Domain\Exception\InvalidDomainIdException; +use Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade; use Shopsys\FrameworkBundle\Component\Router\Security\Annotation\CsrfProtection; use Shopsys\FrameworkBundle\Controller\Admin\AdminBaseController; use Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider; use Shopsys\FrameworkBundle\Model\Article\Exception\ArticleNotFoundException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\Routing\Annotation\Route; class BlogArticleController extends AdminBaseController { - private const ALL_DOMAINS = 0; - private const SESSION_BLOG_ARTICLES_SELECTED_DOMAIN_ID = 'blog_articles_selected_domain_id'; - /** * @param \App\Model\Blog\Article\BlogArticleFacade $blogArticleFacade * @param \App\Model\Blog\Article\BlogArticleDataFactory $blogArticleDataFactory - * @param \Shopsys\FrameworkBundle\Component\Domain\AdminDomainTabsFacade $adminDomainTabsFacade * @param \Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider $breadcrumbOverrider * @param \Shopsys\FrameworkBundle\Component\ConfirmDelete\ConfirmDeleteResponseFactory $confirmDeleteResponseFactory * @param \App\Model\Blog\Article\BlogArticleGridFactory $blogArticleGridFactory - * @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session - * @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain + * @param \Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade */ public function __construct( - private BlogArticleFacade $blogArticleFacade, - private BlogArticleDataFactory $blogArticleDataFactory, - private AdminDomainTabsFacade $adminDomainTabsFacade, - private BreadcrumbOverrider $breadcrumbOverrider, - private ConfirmDeleteResponseFactory $confirmDeleteResponseFactory, - private BlogArticleGridFactory $blogArticleGridFactory, - private SessionInterface $session, - private Domain $domain, + private readonly BlogArticleFacade $blogArticleFacade, + private readonly BlogArticleDataFactory $blogArticleDataFactory, + private readonly BreadcrumbOverrider $breadcrumbOverrider, + private readonly ConfirmDeleteResponseFactory $confirmDeleteResponseFactory, + private readonly BlogArticleGridFactory $blogArticleGridFactory, + private readonly AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade, ) { } /** * @Route("/blog/article/list/", name="admin_blogarticle_list") - * @param \Symfony\Component\HttpFoundation\Request $request * @return \Symfony\Component\HttpFoundation\Response */ - public function listAction(Request $request): Response + public function listAction(): Response { - if (count($this->domain->getAll()) > 1) { - if ($request->query->has('domain')) { - $domainId = (int)$request->query->get('domain'); - } else { - $domainId = (int)$this->session->get(self::SESSION_BLOG_ARTICLES_SELECTED_DOMAIN_ID, self::ALL_DOMAINS); - } - } else { - $domainId = self::ALL_DOMAINS; - } + $domainFilterNamespace = 'blog-article'; + $selectedDomainId = $this->adminDomainFilterTabsFacade->getSelectedDomainId($domainFilterNamespace); - if ($domainId !== self::ALL_DOMAINS) { - try { - $this->domain->getDomainConfigById($domainId); - } catch (InvalidDomainIdException $ex) { - $domainId = self::ALL_DOMAINS; - } - } - - $this->session->set(self::SESSION_BLOG_ARTICLES_SELECTED_DOMAIN_ID, $domainId); - - $grid = $this->blogArticleGridFactory->create($domainId); - $blogArticlesCountOnSelectedDomain = $this->blogArticleFacade->getAllArticlesCountByDomainId($this->adminDomainTabsFacade->getSelectedDomainId()); + $grid = $this->blogArticleGridFactory->create($selectedDomainId); return $this->render('Admin/Content/Blog/Article/list.html.twig', [ 'gridView' => $grid->createView(), - 'blogArticlesCountOnSelectedDomain' => $blogArticlesCountOnSelectedDomain, + 'domainFilterNamespace' => $domainFilterNamespace, ]); } @@ -202,17 +173,4 @@ public function deleteConfirmAction(int $id): Response return $this->confirmDeleteResponseFactory->createDeleteResponse($message, 'admin_blogarticle_delete', $id); } - - /** - * @return \Symfony\Component\HttpFoundation\Response - */ - public function listDomainTabsAction(): Response - { - $domainId = $this->session->get(self::SESSION_BLOG_ARTICLES_SELECTED_DOMAIN_ID, self::ALL_DOMAINS); - - return $this->render('Admin/Content/Blog/Article/domainTabs.html.twig', [ - 'domainConfigs' => $this->domain->getAll(), - 'selectedDomainId' => $domainId, - ]); - } } diff --git a/app/src/Controller/Admin/BlogCategoryController.php b/app/src/Controller/Admin/BlogCategoryController.php index 0605917bcf..f944d1bc6f 100644 --- a/app/src/Controller/Admin/BlogCategoryController.php +++ b/app/src/Controller/Admin/BlogCategoryController.php @@ -9,35 +9,28 @@ use App\Model\Blog\Category\BlogCategoryFacade; use App\Model\Blog\Category\Exception\BlogCategoryNotFoundException; use Nette\Utils\Json; -use Shopsys\FrameworkBundle\Component\Domain\Domain; -use Shopsys\FrameworkBundle\Component\Domain\Exception\InvalidDomainIdException; +use Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade; use Shopsys\FrameworkBundle\Component\Router\Security\Annotation\CsrfProtection; use Shopsys\FrameworkBundle\Controller\Admin\AdminBaseController; use Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\Routing\Annotation\Route; class BlogCategoryController extends AdminBaseController { - private const ALL_DOMAINS = 0; - private const SESSION_BLOG_CATEGORIES_SELECTED_DOMAIN_ID = 'blog_categories_selected_domain_id'; - /** * @param \App\Model\Blog\Category\BlogCategoryFacade $blogCategoryFacade * @param \App\Model\Blog\Category\BlogCategoryDataFactory $blogCategoryDataFactory - * @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session - * @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain * @param \Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider $breadcrumbOverrider + * @param \Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade */ public function __construct( - private BlogCategoryFacade $blogCategoryFacade, - private BlogCategoryDataFactory $blogCategoryDataFactory, - private SessionInterface $session, - private Domain $domain, - private BreadcrumbOverrider $breadcrumbOverrider, + private readonly BlogCategoryFacade $blogCategoryFacade, + private readonly BlogCategoryDataFactory $blogCategoryDataFactory, + private readonly BreadcrumbOverrider $breadcrumbOverrider, + private readonly AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade, ) { } @@ -128,35 +121,24 @@ public function newAction(Request $request): Response */ public function listAction(Request $request): Response { - if (count($this->domain->getAll()) > 1) { - if ($request->query->has('domain')) { - $domainId = (int)$request->query->get('domain'); - } else { - $domainId = (int)$this->session->get(self::SESSION_BLOG_CATEGORIES_SELECTED_DOMAIN_ID, self::ALL_DOMAINS); - } - } else { - $domainId = self::ALL_DOMAINS; - } - - if ($domainId !== self::ALL_DOMAINS) { - try { - $this->domain->getDomainConfigById($domainId); - } catch (InvalidDomainIdException $ex) { - $domainId = self::ALL_DOMAINS; - } - } - - $this->session->set(self::SESSION_BLOG_CATEGORIES_SELECTED_DOMAIN_ID, $domainId); + $domainFilterNamespace = 'blog-category'; + $selectedDomainId = $this->adminDomainFilterTabsFacade->getSelectedDomainId($domainFilterNamespace); - if ($domainId === self::ALL_DOMAINS) { - $blogCategoriesWithPreloadedChildren = $this->blogCategoryFacade->getAllBlogCategoriesWithPreloadedChildren($request->getLocale()); + if ($selectedDomainId === null) { + $blogCategoriesWithPreloadedChildren = $this->blogCategoryFacade->getAllBlogCategoriesWithPreloadedChildren( + $request->getLocale(), + ); } else { - $blogCategoriesWithPreloadedChildren = $this->blogCategoryFacade->getVisibleBlogCategoriesWithPreloadedChildrenOnDomain($domainId, $request->getLocale()); + $blogCategoriesWithPreloadedChildren = $this->blogCategoryFacade->getVisibleBlogCategoriesWithPreloadedChildrenOnDomain( + $selectedDomainId, + $request->getLocale(), + ); } return $this->render('Admin/Content/Blog/Category/list.html.twig', [ 'blogCategoriesWithPreloadedChildren' => $blogCategoriesWithPreloadedChildren, - 'isForAllDomains' => ($domainId === self::ALL_DOMAINS), + 'isForAllDomains' => ($selectedDomainId === null), + 'domainFilterNamespace' => $domainFilterNamespace, ]); } @@ -202,19 +184,6 @@ public function deleteAction(int $id): Response return $this->redirectToRoute('admin_blogcategory_list'); } - /** - * @return \Symfony\Component\HttpFoundation\Response - */ - public function listDomainTabsAction(): Response - { - $domainId = $this->session->get(self::SESSION_BLOG_CATEGORIES_SELECTED_DOMAIN_ID, self::ALL_DOMAINS); - - return $this->render('Admin/Content/Blog/Category/domainTabs.html.twig', [ - 'domainConfigs' => $this->domain->getAll(), - 'selectedDomainId' => $domainId, - ]); - } - /** * @Route("/blog/category/branch/{domainId}/{id}", requirements={"domainId" = "\d+", "id" = "\d+"}, condition="request.isXmlHttpRequest()", name="admin_blogcategory_loadbranchjson") * @param int $domainId diff --git a/app/src/Controller/Admin/CategoryController.php b/app/src/Controller/Admin/CategoryController.php index 10e6e8f880..507ec10541 100644 --- a/app/src/Controller/Admin/CategoryController.php +++ b/app/src/Controller/Admin/CategoryController.php @@ -6,14 +6,13 @@ use App\Component\Form\FormBuilderHelper; use App\Model\CategorySeo\ReadyCategorySeoMixFacade; +use Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade; use Shopsys\FrameworkBundle\Component\Domain\Domain; -use Shopsys\FrameworkBundle\Component\Domain\Exception\InvalidDomainIdException; use Shopsys\FrameworkBundle\Controller\Admin\CategoryController as BaseCategoryController; use Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider; use Shopsys\FrameworkBundle\Model\Category\CategoryDataFactoryInterface; use Shopsys\FrameworkBundle\Model\Category\CategoryFacade; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; @@ -27,18 +26,18 @@ class CategoryController extends BaseCategoryController /** * @param \App\Model\Category\CategoryFacade $categoryFacade * @param \App\Model\Category\CategoryDataFactory $categoryDataFactory - * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack * @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain * @param \Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider $breadcrumbOverrider + * @param \Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade * @param \App\Component\Form\FormBuilderHelper $formBuilderHelper * @param \App\Model\CategorySeo\ReadyCategorySeoMixFacade $categorySeoMixFacade */ public function __construct( CategoryFacade $categoryFacade, CategoryDataFactoryInterface $categoryDataFactory, - RequestStack $requestStack, Domain $domain, BreadcrumbOverrider $breadcrumbOverrider, + AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade, private readonly FormBuilderHelper $formBuilderHelper, private readonly ReadyCategorySeoMixFacade $categorySeoMixFacade, ) { @@ -47,7 +46,7 @@ public function __construct( $categoryDataFactory, $domain, $breadcrumbOverrider, - $requestStack, + $adminDomainFilterTabsFacade, ); } @@ -58,35 +57,24 @@ public function __construct( */ public function listAction(Request $request): Response { - if (count($this->domain->getAll()) > 1) { - if ($request->query->has('domain')) { - $domainId = (int)$request->query->get('domain'); - } else { - $domainId = (int)$this->requestStack->getSession()->get('categories_selected_domain_id', static::ALL_DOMAINS); - } - } else { - $domainId = static::ALL_DOMAINS; - } - - if ($domainId !== static::ALL_DOMAINS) { - try { - $this->domain->getDomainConfigById($domainId); - } catch (InvalidDomainIdException $ex) { - $domainId = static::ALL_DOMAINS; - } - } - - $this->requestStack->getSession()->set('categories_selected_domain_id', $domainId); + $domainFilterNamespace = 'category'; + $selectedDomainId = $this->adminDomainFilterTabsFacade->getSelectedDomainId($domainFilterNamespace); - if ($domainId === static::ALL_DOMAINS) { - $categoriesWithPreloadedChildren = $this->categoryFacade->getAllCategoriesWithPreloadedChildren($request->getLocale()); + if ($selectedDomainId === null) { + $categoriesWithPreloadedChildren = $this->categoryFacade->getAllCategoriesWithPreloadedChildren( + $request->getLocale(), + ); } else { - $categoriesWithPreloadedChildren = $this->categoryFacade->getVisibleCategoriesWithPreloadedChildrenForDomain($domainId, $request->getLocale()); + $categoriesWithPreloadedChildren = $this->categoryFacade->getVisibleCategoriesWithPreloadedChildrenForDomain( + $selectedDomainId, + $request->getLocale(), + ); } return $this->render('/Admin/Content/Category/list.html.twig', [ 'categoriesWithPreloadedChildren' => $categoriesWithPreloadedChildren, - 'isForAllDomains' => ($domainId === static::ALL_DOMAINS), + 'isForAllDomains' => ($selectedDomainId === null), + 'domainFilterNamespace' => $domainFilterNamespace, 'disabledFormFields' => $this->formBuilderHelper->hasFormDisabledFields(), 'getAllCategoryIdsInSeoMixes' => $this->categorySeoMixFacade->getAllCategoryIdsInSeoMixes(), ]); diff --git a/app/src/Model/Blog/Article/BlogArticleGridFactory.php b/app/src/Model/Blog/Article/BlogArticleGridFactory.php index 7fe6860d9d..68b1ed2faf 100644 --- a/app/src/Model/Blog/Article/BlogArticleGridFactory.php +++ b/app/src/Model/Blog/Article/BlogArticleGridFactory.php @@ -17,20 +17,19 @@ class BlogArticleGridFactory * @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain */ public function __construct( - private BlogArticleRepository $blogArticleRepository, - private GridFactory $gridFactory, - private Domain $domain, + private readonly BlogArticleRepository $blogArticleRepository, + private readonly GridFactory $gridFactory, + private readonly Domain $domain, ) { } /** - * @param int $domainId - * @throws \Shopsys\FrameworkBundle\Component\Grid\Exception\DuplicateColumnIdException + * @param int|null $domainId * @return \Shopsys\FrameworkBundle\Component\Grid\Grid */ - public function create(int $domainId): Grid + public function create(?int $domainId): Grid { - if ($domainId === 0) { + if ($domainId === null) { $locale = $this->domain->getLocale(); $queryBuilder = $this->blogArticleRepository->getAllBlogArticlesByLocaleQueryBuilder( $locale, diff --git a/app/templates/Admin/Content/Blog/Article/domainTabs.html.twig b/app/templates/Admin/Content/Blog/Article/domainTabs.html.twig deleted file mode 100644 index cbda2aa1de..0000000000 --- a/app/templates/Admin/Content/Blog/Article/domainTabs.html.twig +++ /dev/null @@ -1,27 +0,0 @@ -{% if domainConfigs|length > 1 %} -