From 65291e6c6ae1807f99ba3f2973a66fab0e130b92 Mon Sep 17 00:00:00 2001 From: roadiz-ci Date: Thu, 16 Jan 2025 19:03:35 +0000 Subject: [PATCH] Merge branch hotfix/v2.4.7 --- .../AbstractAjaxExplorerController.php | 29 ++++++++++++++++++ .../AjaxCustomFormsExplorerController.php | 17 ++--------- .../AjaxDocumentsExplorerController.php | 11 +------ .../AjaxEntitiesExplorerController.php | 11 +------ .../AjaxFoldersExplorerController.php | 3 ++ .../AjaxNodesExplorerController.php | 30 +++++++++---------- src/Explorer/NodeTypeExplorerItem.php | 2 -- src/Resources/app/api/FolderExplorerApi.js | 1 - 8 files changed, 51 insertions(+), 53 deletions(-) create mode 100644 src/AjaxControllers/AbstractAjaxExplorerController.php diff --git a/src/AjaxControllers/AbstractAjaxExplorerController.php b/src/AjaxControllers/AbstractAjaxExplorerController.php new file mode 100644 index 00000000..fb306e85 --- /dev/null +++ b/src/AjaxControllers/AbstractAjaxExplorerController.php @@ -0,0 +1,29 @@ +eventDispatcher->dispatch(new ExplorerEntityListEvent($entity, $criteria, $ordering)); + + return parent::createEntityListManager($event->getEntityName(), $event->getCriteria(), $event->getOrdering()); + } +} diff --git a/src/AjaxControllers/AjaxCustomFormsExplorerController.php b/src/AjaxControllers/AjaxCustomFormsExplorerController.php index e53b9b81..053ee260 100644 --- a/src/AjaxControllers/AjaxCustomFormsExplorerController.php +++ b/src/AjaxControllers/AjaxCustomFormsExplorerController.php @@ -7,25 +7,14 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\Exception\NotSupported; use RZ\Roadiz\CoreBundle\Entity\CustomForm; -use RZ\Roadiz\CoreBundle\Explorer\ExplorerItemFactoryInterface; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Exception\InvalidParameterException; -use Symfony\Component\Serializer\SerializerInterface; -final class AjaxCustomFormsExplorerController extends AbstractAjaxController +final class AjaxCustomFormsExplorerController extends AbstractAjaxExplorerController { - public function __construct( - private readonly ExplorerItemFactoryInterface $explorerItemFactory, - SerializerInterface $serializer, - ) { - parent::__construct($serializer); - } - - /** - * @return Response JSON response - */ - public function indexAction(Request $request): Response + public function indexAction(Request $request): JsonResponse { $this->denyAccessUnlessGranted('ROLE_ACCESS_CUSTOMFORMS'); diff --git a/src/AjaxControllers/AjaxDocumentsExplorerController.php b/src/AjaxControllers/AjaxDocumentsExplorerController.php index 166bf36c..64fb33ff 100644 --- a/src/AjaxControllers/AjaxDocumentsExplorerController.php +++ b/src/AjaxControllers/AjaxDocumentsExplorerController.php @@ -6,21 +6,12 @@ use RZ\Roadiz\CoreBundle\Entity\Document; use RZ\Roadiz\CoreBundle\Entity\Folder; -use RZ\Roadiz\CoreBundle\Explorer\ExplorerItemFactoryInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Exception\InvalidParameterException; -use Symfony\Component\Serializer\SerializerInterface; -final class AjaxDocumentsExplorerController extends AbstractAjaxController +final class AjaxDocumentsExplorerController extends AbstractAjaxExplorerController { - public function __construct( - private readonly ExplorerItemFactoryInterface $explorerItemFactory, - SerializerInterface $serializer, - ) { - parent::__construct($serializer); - } - public function indexAction(Request $request): JsonResponse { $this->denyAccessUnlessGranted('ROLE_ACCESS_DOCUMENTS'); diff --git a/src/AjaxControllers/AjaxEntitiesExplorerController.php b/src/AjaxControllers/AjaxEntitiesExplorerController.php index c8116a9f..7cbdd205 100644 --- a/src/AjaxControllers/AjaxEntitiesExplorerController.php +++ b/src/AjaxControllers/AjaxEntitiesExplorerController.php @@ -9,23 +9,14 @@ use RZ\Roadiz\Core\AbstractEntities\PersistableInterface; use RZ\Roadiz\CoreBundle\Configuration\JoinNodeTypeFieldConfiguration; use RZ\Roadiz\CoreBundle\Entity\NodeTypeField; -use RZ\Roadiz\CoreBundle\Explorer\ExplorerItemFactoryInterface; use Symfony\Component\Config\Definition\Processor; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; -use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\Yaml\Yaml; -final class AjaxEntitiesExplorerController extends AbstractAjaxController +final class AjaxEntitiesExplorerController extends AbstractAjaxExplorerController { - public function __construct( - private readonly ExplorerItemFactoryInterface $explorerItemFactory, - SerializerInterface $serializer, - ) { - parent::__construct($serializer); - } - protected function getFieldConfiguration(NodeTypeField $nodeTypeField): array { if ( diff --git a/src/AjaxControllers/AjaxFoldersExplorerController.php b/src/AjaxControllers/AjaxFoldersExplorerController.php index 12cbfcc5..cc3c80f6 100644 --- a/src/AjaxControllers/AjaxFoldersExplorerController.php +++ b/src/AjaxControllers/AjaxFoldersExplorerController.php @@ -8,6 +8,9 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; +/** + * Only used to display folders list in document explorer filtering aside. + */ final class AjaxFoldersExplorerController extends AbstractAjaxController { public function indexAction(Request $request): JsonResponse diff --git a/src/AjaxControllers/AjaxNodesExplorerController.php b/src/AjaxControllers/AjaxNodesExplorerController.php index 8e7412a6..2f98f752 100644 --- a/src/AjaxControllers/AjaxNodesExplorerController.php +++ b/src/AjaxControllers/AjaxNodesExplorerController.php @@ -6,10 +6,11 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\Exception\NotSupported; +use RZ\Roadiz\CoreBundle\Bag\NodeTypes; use RZ\Roadiz\CoreBundle\Entity\Node; use RZ\Roadiz\CoreBundle\Entity\NodesSources; +use RZ\Roadiz\CoreBundle\Entity\NodeType; use RZ\Roadiz\CoreBundle\Entity\Tag; -use RZ\Roadiz\CoreBundle\EntityApi\NodeTypeApi; use RZ\Roadiz\CoreBundle\Enum\NodeStatus; use RZ\Roadiz\CoreBundle\Explorer\AbstractExplorerItem; use RZ\Roadiz\CoreBundle\Explorer\ExplorerItemFactoryInterface; @@ -19,20 +20,21 @@ use RZ\Roadiz\CoreBundle\Security\Authorization\Voter\NodeVoter; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Exception\InvalidParameterException; use Symfony\Component\Serializer\SerializerInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; -final class AjaxNodesExplorerController extends AbstractAjaxController +final class AjaxNodesExplorerController extends AbstractAjaxExplorerController { public function __construct( - private readonly ExplorerItemFactoryInterface $explorerItemFactory, private readonly ClientRegistry $clientRegistry, private readonly NodeSourceSearchHandlerInterface $nodeSourceSearchHandler, - private readonly NodeTypeApi $nodeTypeApi, + private readonly NodeTypes $nodeTypesBag, + ExplorerItemFactoryInterface $explorerItemFactory, + EventDispatcherInterface $eventDispatcher, SerializerInterface $serializer, ) { - parent::__construct($serializer); + parent::__construct($explorerItemFactory, $eventDispatcher, $serializer); } protected function getItemPerPage(): int @@ -45,10 +47,7 @@ protected function isSearchEngineAvailable(Request $request): bool return '' !== $request->get('search') && null !== $this->clientRegistry->getClient(); } - /** - * @return Response JSON response - */ - public function indexAction(Request $request): Response + public function indexAction(Request $request): JsonResponse { // Only requires Search permission for nodes $this->denyAccessUnlessGranted(NodeVoter::SEARCH); @@ -87,13 +86,12 @@ protected function parseFilterFromRequest(Request $request): array } if ($request->query->has('nodeTypes') && count($request->get('nodeTypes')) > 0) { - $nodeTypeNames = array_map('trim', $request->get('nodeTypes')); - - $nodeTypes = $this->nodeTypeApi->getBy([ - 'name' => $nodeTypeNames, - ]); + /** @var NodeType[] $nodeTypes */ + $nodeTypes = array_filter(array_map(function ($nodeTypeName) { + return $this->nodeTypesBag->get(trim($nodeTypeName)); + }, $request->get('nodeTypes'))); - if (null !== $nodeTypes && count($nodeTypes) > 0) { + if (count($nodeTypes) > 0) { $arrayFilter['nodeType'] = $nodeTypes; } } diff --git a/src/Explorer/NodeTypeExplorerItem.php b/src/Explorer/NodeTypeExplorerItem.php index 858eebd2..41a997e3 100644 --- a/src/Explorer/NodeTypeExplorerItem.php +++ b/src/Explorer/NodeTypeExplorerItem.php @@ -53,8 +53,6 @@ protected function getColor(): ?string return $this->nodeType->getColor(); } - - public function toArray(): array { return [ diff --git a/src/Resources/app/api/FolderExplorerApi.js b/src/Resources/app/api/FolderExplorerApi.js index d591c8fd..2505cbe4 100644 --- a/src/Resources/app/api/FolderExplorerApi.js +++ b/src/Resources/app/api/FolderExplorerApi.js @@ -26,7 +26,6 @@ export function getFolders() { } }) .catch((error) => { - // TODO // Log request error or display a message throw new Error(error) })