diff --git a/lib/Rozier/src/AjaxControllers/AbstractAjaxController.php b/lib/Rozier/src/AjaxControllers/AbstractAjaxController.php index 73f33d01..54027996 100644 --- a/lib/Rozier/src/AjaxControllers/AbstractAjaxController.php +++ b/lib/Rozier/src/AjaxControllers/AbstractAjaxController.php @@ -4,8 +4,11 @@ namespace Themes\Rozier\AjaxControllers; +use JMS\Serializer\SerializationContext; +use JMS\Serializer\SerializerInterface; use RZ\Roadiz\Core\AbstractEntities\TranslationInterface; use RZ\Roadiz\CoreBundle\Entity\Translation; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Themes\Rozier\RozierApp; @@ -16,6 +19,11 @@ */ abstract class AbstractAjaxController extends RozierApp { + public function __construct( + protected readonly SerializerInterface $serializer + ) { + } + protected static array $validMethods = [ Request::METHOD_POST, Request::METHOD_GET, @@ -83,4 +91,26 @@ protected function sortIsh(array &$arr, array $map): array return $return; } + + /** + * @param array $data + * @return JsonResponse + */ + protected function createSerializedResponse(array $data): JsonResponse + { + return new JsonResponse( + $this->serializer->serialize( + $data, + 'json', + SerializationContext::create()->setGroups([ + 'document_display', + 'explorer_thumbnail', + 'model' + ]) + ), + 200, + [], + true + ); + } } diff --git a/lib/Rozier/src/AjaxControllers/AjaxAbstractFieldsController.php b/lib/Rozier/src/AjaxControllers/AjaxAbstractFieldsController.php index 84177e70..3fc4ab69 100644 --- a/lib/Rozier/src/AjaxControllers/AjaxAbstractFieldsController.php +++ b/lib/Rozier/src/AjaxControllers/AjaxAbstractFieldsController.php @@ -4,6 +4,7 @@ namespace Themes\Rozier\AjaxControllers; +use JMS\Serializer\SerializerInterface; use RZ\Roadiz\Core\AbstractEntities\AbstractField; use RZ\Roadiz\Core\Handlers\HandlerFactoryInterface; use Symfony\Component\HttpFoundation\JsonResponse; @@ -13,8 +14,11 @@ abstract class AjaxAbstractFieldsController extends AbstractAjaxController { - public function __construct(protected readonly HandlerFactoryInterface $handlerFactory) - { + public function __construct( + protected readonly HandlerFactoryInterface $handlerFactory, + SerializerInterface $serializer + ) { + parent::__construct($serializer); } protected function findEntity(int|string $entityId): ?AbstractField diff --git a/lib/Rozier/src/AjaxControllers/AjaxCustomFormsExplorerController.php b/lib/Rozier/src/AjaxControllers/AjaxCustomFormsExplorerController.php index c790544a..8450efa2 100644 --- a/lib/Rozier/src/AjaxControllers/AjaxCustomFormsExplorerController.php +++ b/lib/Rozier/src/AjaxControllers/AjaxCustomFormsExplorerController.php @@ -6,9 +6,9 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\Exception\NotSupported; +use JMS\Serializer\SerializerInterface; 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; @@ -17,7 +17,9 @@ final class AjaxCustomFormsExplorerController extends AbstractAjaxController { public function __construct( private readonly ExplorerItemFactoryInterface $explorerItemFactory, + SerializerInterface $serializer ) { + parent::__construct($serializer); } /** @@ -46,17 +48,13 @@ public function indexAction(Request $request): Response $customFormsArray = $this->normalizeCustomForms($customForms); - $responseArray = [ + return $this->createSerializedResponse([ 'status' => 'confirm', 'statusCode' => 200, 'customForms' => $customFormsArray, 'customFormsCount' => count($customForms), 'filters' => $listManager->getAssignation(), - ]; - - return new JsonResponse( - $responseArray - ); + ]); } /** @@ -90,15 +88,11 @@ public function listAction(Request $request): Response $customFormsArray = $this->normalizeCustomForms($customForms); } - $responseArray = [ + return $this->createSerializedResponse([ 'status' => 'confirm', 'statusCode' => 200, 'forms' => $customFormsArray - ]; - - return new JsonResponse( - $responseArray - ); + ]); } /** diff --git a/lib/Rozier/src/AjaxControllers/AjaxDocumentsExplorerController.php b/lib/Rozier/src/AjaxControllers/AjaxDocumentsExplorerController.php index 28757ae0..17300f07 100644 --- a/lib/Rozier/src/AjaxControllers/AjaxDocumentsExplorerController.php +++ b/lib/Rozier/src/AjaxControllers/AjaxDocumentsExplorerController.php @@ -4,6 +4,7 @@ namespace Themes\Rozier\AjaxControllers; +use JMS\Serializer\SerializerInterface; use RZ\Roadiz\CoreBundle\Entity\Document; use RZ\Roadiz\CoreBundle\Entity\Folder; use RZ\Roadiz\CoreBundle\Explorer\ExplorerItemFactoryInterface; @@ -14,8 +15,10 @@ final class AjaxDocumentsExplorerController extends AbstractAjaxController { public function __construct( - private readonly ExplorerItemFactoryInterface $explorerItemFactory + private readonly ExplorerItemFactoryInterface $explorerItemFactory, + SerializerInterface $serializer ) { + parent::__construct($serializer); } public function indexAction(Request $request): JsonResponse @@ -70,7 +73,7 @@ public function indexAction(Request $request): JsonResponse ]); } - return new JsonResponse( + return $this->createSerializedResponse( $responseArray ); } @@ -104,16 +107,12 @@ public function listAction(Request $request): JsonResponse $documentsArray = $this->normalizeDocuments($documents); } - $responseArray = [ + return $this->createSerializedResponse([ 'status' => 'confirm', 'statusCode' => 200, 'documents' => $documentsArray, 'trans' => $this->getTrans() - ]; - - return new JsonResponse( - $responseArray - ); + ]); } /** diff --git a/lib/Rozier/src/AjaxControllers/AjaxEntitiesExplorerController.php b/lib/Rozier/src/AjaxControllers/AjaxEntitiesExplorerController.php index bbf22574..dcab945e 100644 --- a/lib/Rozier/src/AjaxControllers/AjaxEntitiesExplorerController.php +++ b/lib/Rozier/src/AjaxControllers/AjaxEntitiesExplorerController.php @@ -5,6 +5,7 @@ namespace Themes\Rozier\AjaxControllers; use Doctrine\ORM\EntityManager; +use JMS\Serializer\SerializerInterface; use RZ\Roadiz\Core\AbstractEntities\AbstractField; use RZ\Roadiz\Core\AbstractEntities\PersistableInterface; use RZ\Roadiz\CoreBundle\Configuration\JoinNodeTypeFieldConfiguration; @@ -20,7 +21,9 @@ final class AjaxEntitiesExplorerController extends AbstractAjaxController { public function __construct( private readonly ExplorerItemFactoryInterface $explorerItemFactory, + SerializerInterface $serializer ) { + parent::__construct($serializer); } /** @@ -89,16 +92,12 @@ public function indexAction(Request $request): JsonResponse $entitiesArray = $this->normalizeEntities($entities, $configuration); - $responseArray = [ + return $this->createSerializedResponse([ 'status' => 'confirm', 'statusCode' => 200, 'entities' => $entitiesArray, 'filters' => $listManager->getAssignation(), - ]; - - return new JsonResponse( - $responseArray - ); + ]); } public function listAction(Request $request): JsonResponse @@ -142,15 +141,11 @@ public function listAction(Request $request): JsonResponse $entitiesArray = $this->normalizeEntities($entities, $configuration); } - $responseArray = [ + return $this->createSerializedResponse([ 'status' => 'confirm', 'statusCode' => 200, 'items' => $entitiesArray - ]; - - return new JsonResponse( - $responseArray - ); + ]); } /** diff --git a/lib/Rozier/src/AjaxControllers/AjaxExplorerProviderController.php b/lib/Rozier/src/AjaxControllers/AjaxExplorerProviderController.php index c1b3aa0e..32e8092b 100644 --- a/lib/Rozier/src/AjaxControllers/AjaxExplorerProviderController.php +++ b/lib/Rozier/src/AjaxControllers/AjaxExplorerProviderController.php @@ -4,6 +4,7 @@ namespace Themes\Rozier\AjaxControllers; +use JMS\Serializer\SerializerInterface; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; @@ -11,13 +12,15 @@ use RZ\Roadiz\CoreBundle\Explorer\ExplorerProviderInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Exception\InvalidParameterException; class AjaxExplorerProviderController extends AbstractAjaxController { - public function __construct(private readonly ContainerInterface $psrContainer) - { + public function __construct( + private readonly ContainerInterface $psrContainer, + SerializerInterface $serializer + ) { + parent::__construct($serializer); } /** @@ -91,17 +94,12 @@ public function indexAction(Request $request): JsonResponse } } - $responseArray = [ + return $this->createSerializedResponse([ 'status' => 'confirm', 'statusCode' => 200, 'entities' => $entitiesArray, 'filters' => $provider->getFilters($options), - ]; - - return new JsonResponse( - $responseArray, - Response::HTTP_PARTIAL_CONTENT - ); + ]); } /** @@ -136,14 +134,10 @@ public function listAction(Request $request): JsonResponse } } - $responseArray = [ + return $this->createSerializedResponse([ 'status' => 'confirm', 'statusCode' => 200, 'items' => $entitiesArray - ]; - - return new JsonResponse( - $responseArray - ); + ]); } } diff --git a/lib/Rozier/src/AjaxControllers/AjaxFolderTreeController.php b/lib/Rozier/src/AjaxControllers/AjaxFolderTreeController.php index f4495bcd..f9339b22 100644 --- a/lib/Rozier/src/AjaxControllers/AjaxFolderTreeController.php +++ b/lib/Rozier/src/AjaxControllers/AjaxFolderTreeController.php @@ -4,6 +4,7 @@ namespace Themes\Rozier\AjaxControllers; +use JMS\Serializer\SerializerInterface; use RZ\Roadiz\CoreBundle\Entity\Folder; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -12,8 +13,11 @@ final class AjaxFolderTreeController extends AbstractAjaxController { - public function __construct(private readonly TreeWidgetFactory $treeWidgetFactory) - { + public function __construct( + private readonly TreeWidgetFactory $treeWidgetFactory, + SerializerInterface $serializer + ) { + parent::__construct($serializer); } public function getTreeAction(Request $request): JsonResponse @@ -56,14 +60,10 @@ public function getTreeAction(Request $request): JsonResponse $this->assignation['folderTree'] = $folderTree; - $responseArray = [ + return $this->createSerializedResponse([ 'statusCode' => '200', 'status' => 'success', 'folderTree' => $this->getTwig()->render('@RoadizRozier/widgets/folderTree/folderTree.html.twig', $this->assignation), - ]; - - return new JsonResponse( - $responseArray - ); + ]); } } diff --git a/lib/Rozier/src/AjaxControllers/AjaxFoldersController.php b/lib/Rozier/src/AjaxControllers/AjaxFoldersController.php index 7c88b1e5..3e2c68f3 100644 --- a/lib/Rozier/src/AjaxControllers/AjaxFoldersController.php +++ b/lib/Rozier/src/AjaxControllers/AjaxFoldersController.php @@ -4,6 +4,7 @@ namespace Themes\Rozier\AjaxControllers; +use JMS\Serializer\SerializerInterface; use RZ\Roadiz\CoreBundle\Entity\Folder; use RZ\Roadiz\CoreBundle\EntityHandler\FolderHandler; use RZ\Roadiz\Core\Handlers\HandlerFactoryInterface; @@ -14,8 +15,11 @@ final class AjaxFoldersController extends AbstractAjaxController { - public function __construct(private readonly HandlerFactoryInterface $handlerFactory) - { + public function __construct( + private readonly HandlerFactoryInterface $handlerFactory, + SerializerInterface $serializer + ) { + parent::__construct($serializer); } /* diff --git a/lib/Rozier/src/AjaxControllers/AjaxFoldersExplorerController.php b/lib/Rozier/src/AjaxControllers/AjaxFoldersExplorerController.php index aed2b011..e41aeb20 100644 --- a/lib/Rozier/src/AjaxControllers/AjaxFoldersExplorerController.php +++ b/lib/Rozier/src/AjaxControllers/AjaxFoldersExplorerController.php @@ -25,15 +25,11 @@ public function indexAction(Request $request): JsonResponse ] ); - $responseArray = [ + return $this->createSerializedResponse([ 'status' => 'confirm', 'statusCode' => 200, 'folders' => $this->recurseFolders($folders), - ]; - - return new JsonResponse( - $responseArray - ); + ]); } protected function recurseFolders(?iterable $folders = null): array diff --git a/lib/Rozier/src/AjaxControllers/AjaxNodeTreeController.php b/lib/Rozier/src/AjaxControllers/AjaxNodeTreeController.php index 5358fe1a..88f4db18 100644 --- a/lib/Rozier/src/AjaxControllers/AjaxNodeTreeController.php +++ b/lib/Rozier/src/AjaxControllers/AjaxNodeTreeController.php @@ -4,6 +4,7 @@ namespace Themes\Rozier\AjaxControllers; +use JMS\Serializer\SerializerInterface; use RZ\Roadiz\CoreBundle\Bag\NodeTypes; use RZ\Roadiz\CoreBundle\Entity\Node; use RZ\Roadiz\CoreBundle\Entity\NodeType; @@ -19,8 +20,10 @@ final class AjaxNodeTreeController extends AbstractAjaxController public function __construct( private readonly NodeChrootResolver $nodeChrootResolver, private readonly TreeWidgetFactory $treeWidgetFactory, - private readonly NodeTypes $nodeTypesBag + private readonly NodeTypes $nodeTypesBag, + SerializerInterface $serializer ) { + parent::__construct($serializer); } public function getTreeAction(Request $request): JsonResponse @@ -102,17 +105,13 @@ public function getTreeAction(Request $request): JsonResponse // Need to expose linkedTypes to add data-attributes on widget again $this->assignation['linkedTypes'] = $linkedTypes; - $responseArray = [ + return $this->createSerializedResponse([ 'statusCode' => '200', 'status' => 'success', 'linkedTypes' => array_map(function (NodeType $nodeType) { return $nodeType->getName(); }, $linkedTypes), 'nodeTree' => trim($this->getTwig()->render('@RoadizRozier/widgets/nodeTree/nodeTree.html.twig', $this->assignation)), - ]; - - return new JsonResponse( - $responseArray - ); + ]); } } diff --git a/lib/Rozier/src/AjaxControllers/AjaxNodeTypesController.php b/lib/Rozier/src/AjaxControllers/AjaxNodeTypesController.php index 67f36efc..3419c2a0 100644 --- a/lib/Rozier/src/AjaxControllers/AjaxNodeTypesController.php +++ b/lib/Rozier/src/AjaxControllers/AjaxNodeTypesController.php @@ -6,6 +6,7 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\Exception\NotSupported; +use JMS\Serializer\SerializerInterface; use RZ\Roadiz\CoreBundle\Entity\NodeType; use RZ\Roadiz\CoreBundle\Explorer\ExplorerItemFactoryInterface; use Symfony\Component\HttpFoundation\JsonResponse; @@ -16,8 +17,10 @@ final class AjaxNodeTypesController extends AbstractAjaxController { public function __construct( - private readonly ExplorerItemFactoryInterface $explorerItemFactory + private readonly ExplorerItemFactoryInterface $explorerItemFactory, + SerializerInterface $serializer ) { + parent::__construct($serializer); } /** @@ -44,17 +47,13 @@ public function indexAction(Request $request): Response $nodeTypes = $listManager->getEntities(); $documentsArray = $this->normalizeNodeType($nodeTypes); - $responseArray = [ + return $this->createSerializedResponse([ 'status' => 'confirm', 'statusCode' => 200, 'nodeTypes' => $documentsArray, 'nodeTypesCount' => count($nodeTypes), 'filters' => $listManager->getAssignation() - ]; - - return new JsonResponse( - $responseArray - ); + ]); } /** @@ -88,15 +87,11 @@ public function listAction(Request $request): Response $nodesArray = $this->normalizeNodeType($nodeTypes); } - $responseArray = [ + return $this->createSerializedResponse([ 'status' => 'confirm', 'statusCode' => 200, 'items' => $nodesArray - ]; - - return new JsonResponse( - $responseArray - ); + ]); } /** diff --git a/lib/Rozier/src/AjaxControllers/AjaxNodesController.php b/lib/Rozier/src/AjaxControllers/AjaxNodesController.php index 3bb02926..cbc5c64a 100644 --- a/lib/Rozier/src/AjaxControllers/AjaxNodesController.php +++ b/lib/Rozier/src/AjaxControllers/AjaxNodesController.php @@ -4,6 +4,7 @@ namespace Themes\Rozier\AjaxControllers; +use JMS\Serializer\SerializerInterface; use Psr\Log\LoggerInterface; use RZ\Roadiz\CoreBundle\Entity\Node; use RZ\Roadiz\CoreBundle\Entity\Tag; @@ -24,7 +25,6 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Workflow\Registry; final class AjaxNodesController extends AbstractAjaxController @@ -35,8 +35,10 @@ public function __construct( private readonly NodeMover $nodeMover, private readonly NodeChrootResolver $nodeChrootResolver, private readonly Registry $workflowRegistry, - private readonly UniqueNodeGenerator $uniqueNodeGenerator + private readonly UniqueNodeGenerator $uniqueNodeGenerator, + SerializerInterface $serializer ) { + parent::__construct($serializer); } /** @@ -60,7 +62,7 @@ public function getTagsAction(Request $request, int $nodeId): JsonResponse $tags[] = $tag->getFullPath(); } - return new JsonResponse( + return $this->createSerializedResponse( $tags ); } diff --git a/lib/Rozier/src/AjaxControllers/AjaxNodesExplorerController.php b/lib/Rozier/src/AjaxControllers/AjaxNodesExplorerController.php index a02bb6fa..b2c924dc 100644 --- a/lib/Rozier/src/AjaxControllers/AjaxNodesExplorerController.php +++ b/lib/Rozier/src/AjaxControllers/AjaxNodesExplorerController.php @@ -6,7 +6,6 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\Exception\NotSupported; -use JMS\Serializer\SerializationContext; use JMS\Serializer\SerializerInterface; use RZ\Roadiz\CoreBundle\Entity\Node; use RZ\Roadiz\CoreBundle\Entity\NodesSources; @@ -27,11 +26,12 @@ final class AjaxNodesExplorerController extends AbstractAjaxController { public function __construct( private readonly ExplorerItemFactoryInterface $explorerItemFactory, - private readonly SerializerInterface $serializer, private readonly ClientRegistry $clientRegistry, private readonly NodeSourceSearchHandlerInterface $nodeSourceSearchHandler, private readonly NodeTypeApi $nodeTypeApi, + SerializerInterface $serializer ) { + parent::__construct($serializer); } protected function getItemPerPage(): int @@ -275,26 +275,4 @@ private function normalizeItem(NodesSources|Node $item, array &$nodesArray): voi $nodesArray[$model->getId()] = $model->toArray(); } } - - /** - * @param array $data - * @return JsonResponse - */ - protected function createSerializedResponse(array $data): JsonResponse - { - return new JsonResponse( - $this->serializer->serialize( - $data, - 'json', - SerializationContext::create()->setGroups([ - 'document_display', - 'explorer_thumbnail', - 'model' - ]) - ), - 200, - [], - true - ); - } } diff --git a/lib/Rozier/src/AjaxControllers/AjaxSearchNodesSourcesController.php b/lib/Rozier/src/AjaxControllers/AjaxSearchNodesSourcesController.php index 89129022..55ec1ec6 100644 --- a/lib/Rozier/src/AjaxControllers/AjaxSearchNodesSourcesController.php +++ b/lib/Rozier/src/AjaxControllers/AjaxSearchNodesSourcesController.php @@ -4,6 +4,7 @@ namespace Themes\Rozier\AjaxControllers; +use JMS\Serializer\SerializerInterface; use RZ\Roadiz\CoreBundle\Entity\NodesSources; use RZ\Roadiz\CoreBundle\Entity\NodesSourcesDocuments; use RZ\Roadiz\CoreBundle\Entity\Translation; @@ -22,8 +23,10 @@ final class AjaxSearchNodesSourcesController extends AbstractAjaxController public function __construct( private readonly DocumentUrlGeneratorInterface $documentUrlGenerator, - private readonly Security $security + private readonly Security $security, + SerializerInterface $serializer ) { + parent::__construct($serializer); } /** @@ -81,7 +84,7 @@ public function searchAction(Request $request): Response */ $responseArray['data'] = array_values($responseArray['data']); - return new JsonResponse( + return $this->createSerializedResponse( $responseArray ); } diff --git a/lib/Rozier/src/AjaxControllers/AjaxTagTreeController.php b/lib/Rozier/src/AjaxControllers/AjaxTagTreeController.php index d35a8346..67544e62 100644 --- a/lib/Rozier/src/AjaxControllers/AjaxTagTreeController.php +++ b/lib/Rozier/src/AjaxControllers/AjaxTagTreeController.php @@ -4,6 +4,7 @@ namespace Themes\Rozier\AjaxControllers; +use JMS\Serializer\SerializerInterface; use RZ\Roadiz\CoreBundle\Entity\Tag; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -12,8 +13,11 @@ final class AjaxTagTreeController extends AbstractAjaxController { - public function __construct(private readonly TreeWidgetFactory $treeWidgetFactory) - { + public function __construct( + private readonly TreeWidgetFactory $treeWidgetFactory, + SerializerInterface $serializer + ) { + parent::__construct($serializer); } public function getTreeAction(Request $request): JsonResponse @@ -56,14 +60,10 @@ public function getTreeAction(Request $request): JsonResponse $this->assignation['tagTree'] = $tagTree; - $responseArray = [ + return $this->createSerializedResponse([ 'statusCode' => '200', 'status' => 'success', 'tagTree' => $this->getTwig()->render('@RoadizRozier/widgets/tagTree/tagTree.html.twig', $this->assignation), - ]; - - return new JsonResponse( - $responseArray - ); + ]); } } diff --git a/lib/Rozier/src/AjaxControllers/AjaxTagsController.php b/lib/Rozier/src/AjaxControllers/AjaxTagsController.php index 2c249ab0..995ae34c 100644 --- a/lib/Rozier/src/AjaxControllers/AjaxTagsController.php +++ b/lib/Rozier/src/AjaxControllers/AjaxTagsController.php @@ -6,6 +6,7 @@ use Doctrine\ORM\OptimisticLockException; use Doctrine\ORM\ORMException; +use JMS\Serializer\SerializerInterface; use RZ\Roadiz\Core\Handlers\HandlerFactoryInterface; use RZ\Roadiz\CoreBundle\Entity\Tag; use RZ\Roadiz\CoreBundle\Entity\Translation; @@ -24,8 +25,10 @@ final class AjaxTagsController extends AbstractAjaxController { public function __construct( private readonly ExplorerItemFactoryInterface $explorerItemFactory, - private readonly HandlerFactoryInterface $handlerFactory + private readonly HandlerFactoryInterface $handlerFactory, + SerializerInterface $serializer ) { + parent::__construct($serializer); } /** @@ -59,15 +62,11 @@ public function indexAction(Request $request): Response $tags = $this->getRepository()->findByParentWithDefaultTranslation(); } - $responseArray = [ + return $this->createSerializedResponse([ 'status' => 'confirm', 'statusCode' => 200, 'tags' => $this->recurseTags($tags, $onlyParents), - ]; - - return new JsonResponse( - $responseArray - ); + ]); } /** @@ -99,15 +98,11 @@ public function listArrayAction(Request $request): JsonResponse $normalizedTags = $this->normalizeTags($tags); } - $responseArray = [ + return $this->createSerializedResponse([ 'status' => 'confirm', 'statusCode' => 200, 'tags' => $normalizedTags - ]; - - return new JsonResponse( - $responseArray - ); + ]); } /** @@ -154,16 +149,12 @@ public function explorerListAction(Request $request): Response $tags = $listManager->getEntities(); - $responseArray = [ + return $this->createSerializedResponse([ 'status' => 'confirm', 'statusCode' => 200, 'tags' => $this->normalizeTags($tags), 'filters' => $listManager->getAssignation(), - ]; - - return new JsonResponse( - $responseArray - ); + ]); } /** @@ -283,7 +274,7 @@ public function searchAction(Request $request): JsonResponse $responseArray[] = $tag->getFullPath(); } - return new JsonResponse( + return $this->createSerializedResponse( $responseArray ); } @@ -292,7 +283,7 @@ public function searchAction(Request $request): JsonResponse * @param array $parameters * @param Tag $tag */ - protected function updatePosition($parameters, Tag $tag): void + protected function updatePosition(array $parameters, Tag $tag): void { /* * First, we set the new parent