Skip to content

Commit

Permalink
Merge tag v2.2.11 into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Mar 7, 2024
1 parent 4ed1fd8 commit b287239
Show file tree
Hide file tree
Showing 28 changed files with 133 additions and 282 deletions.
20 changes: 19 additions & 1 deletion src/AjaxControllers/AbstractAjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Themes\Rozier\AjaxControllers;

use RZ\Roadiz\Core\AbstractEntities\TranslationInterface;
use RZ\Roadiz\CoreBundle\Entity\Translation;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Themes\Rozier\RozierApp;
Expand All @@ -19,14 +21,30 @@ abstract class AbstractAjaxController extends RozierApp
Request::METHOD_GET,
];

protected function getTranslation(Request $request): ?TranslationInterface
{
$translationId = $request->get('translationId', null);
if (\is_numeric($translationId) && $translationId > 0) {
$translation = $this->em()->find(
Translation::class,
$translationId
);
if (null !== $translation) {
return $translation;
}
}

return $this->em()->getRepository(Translation::class)->findDefault();
}

/**
* @param Request $request
* @param string $method
* @param bool $requestCsrfToken
*
* @return bool Return true if request is valid, else throw exception
*/
protected function validateRequest(Request $request, $method = 'POST', $requestCsrfToken = true)
protected function validateRequest(Request $request, string $method = 'POST', bool $requestCsrfToken = true): bool
{
if ($request->get('_action') == "") {
throw new BadRequestHttpException('Wrong action requested');
Expand Down
10 changes: 2 additions & 8 deletions src/AjaxControllers/AjaxAbstractFieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@

abstract class AjaxAbstractFieldsController extends AbstractAjaxController
{
private HandlerFactoryInterface $handlerFactory;

/**
* @param HandlerFactoryInterface $handlerFactory
*/
public function __construct(HandlerFactoryInterface $handlerFactory)
public function __construct(protected readonly HandlerFactoryInterface $handlerFactory)
{
$this->handlerFactory = $handlerFactory;
}

/**
Expand All @@ -30,7 +24,7 @@ public function __construct(HandlerFactoryInterface $handlerFactory)
*
* @return null|Response
*/
protected function handleFieldActions(Request $request, AbstractField $field = null)
protected function handleFieldActions(Request $request, AbstractField $field = null): ?Response
{
/*
* Validate
Expand Down
8 changes: 1 addition & 7 deletions src/AjaxControllers/AjaxAttributeValuesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,7 @@ public function editAction(Request $request, int $attributeValueId): Response
Response::HTTP_PARTIAL_CONTENT
);
}

/**
* @param array $parameters
* @param AttributeValue $attributeValue
*
* @return array
*/

protected function updatePosition(array $parameters, AttributeValue $attributeValue): array
{
$attributable = $attributeValue->getAttributable();
Expand Down
4 changes: 2 additions & 2 deletions src/AjaxControllers/AjaxCustomFormFieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class AjaxCustomFormFieldsController extends AjaxAbstractFieldsController
* such as coming from widgets.
*
* @param Request $request
* @param int $customFormFieldId
* @param int $customFormFieldId
*
* @return Response JSON response
*/
public function editAction(Request $request, int $customFormFieldId)
public function editAction(Request $request, int $customFormFieldId): Response
{
/*
* Validate
Expand Down
7 changes: 2 additions & 5 deletions src/AjaxControllers/AjaxCustomFormsExplorerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@

class AjaxCustomFormsExplorerController extends AbstractAjaxController
{
private UrlGeneratorInterface $urlGenerator;

public function __construct(UrlGeneratorInterface $urlGenerator)
public function __construct(private readonly UrlGeneratorInterface $urlGenerator)
{
$this->urlGenerator = $urlGenerator;
}

/**
Expand Down Expand Up @@ -108,7 +105,7 @@ public function listAction(Request $request): Response
* @param array<CustomForm>|\Traversable<CustomForm> $customForms
* @return array
*/
private function normalizeCustomForms($customForms)
private function normalizeCustomForms(iterable $customForms): array
{
$customFormsArray = [];

Expand Down
28 changes: 7 additions & 21 deletions src/AjaxControllers/AjaxDocumentsExplorerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,27 @@
use RZ\Roadiz\Documents\UrlGenerators\DocumentUrlGeneratorInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Exception\InvalidParameterException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Themes\Rozier\Models\DocumentModel;

class AjaxDocumentsExplorerController extends AbstractAjaxController
{
private RendererInterface $renderer;
private DocumentUrlGeneratorInterface $documentUrlGenerator;
private UrlGeneratorInterface $urlGenerator;
private EmbedFinderFactory $embedFinderFactory;

public function __construct(
RendererInterface $renderer,
DocumentUrlGeneratorInterface $documentUrlGenerator,
UrlGeneratorInterface $urlGenerator,
EmbedFinderFactory $embedFinderFactory
private readonly RendererInterface $renderer,
private readonly DocumentUrlGeneratorInterface $documentUrlGenerator,
private readonly UrlGeneratorInterface $urlGenerator,
private readonly EmbedFinderFactory $embedFinderFactory
) {
$this->renderer = $renderer;
$this->documentUrlGenerator = $documentUrlGenerator;
$this->urlGenerator = $urlGenerator;
$this->embedFinderFactory = $embedFinderFactory;
}

public static array $thumbnailArray = [
"fit" => "40x40",
"quality" => 50,
"inline" => false,
];
/**
* @param Request $request
*
* @return Response JSON response
*/
public function indexAction(Request $request)

public function indexAction(Request $request): JsonResponse
{
$this->denyAccessUnlessGranted('ROLE_ACCESS_DOCUMENTS');

Expand Down Expand Up @@ -108,7 +94,7 @@ public function indexAction(Request $request)
* @param Request $request
* @return JsonResponse
*/
public function listAction(Request $request)
public function listAction(Request $request): JsonResponse
{
$this->denyAccessUnlessGranted('ROLE_ACCESS_DOCUMENTS');

Expand Down
23 changes: 4 additions & 19 deletions src/AjaxControllers/AjaxEntitiesExplorerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,12 @@

class AjaxEntitiesExplorerController extends AbstractAjaxController
{
private RendererInterface $renderer;
private DocumentUrlGeneratorInterface $documentUrlGenerator;
private UrlGeneratorInterface $urlGenerator;
private EmbedFinderFactory $embedFinderFactory;

public function __construct(
RendererInterface $renderer,
DocumentUrlGeneratorInterface $documentUrlGenerator,
UrlGeneratorInterface $urlGenerator,
EmbedFinderFactory $embedFinderFactory
private readonly RendererInterface $renderer,
private readonly DocumentUrlGeneratorInterface $documentUrlGenerator,
private readonly UrlGeneratorInterface $urlGenerator,
private readonly EmbedFinderFactory $embedFinderFactory
) {
$this->renderer = $renderer;
$this->documentUrlGenerator = $documentUrlGenerator;
$this->urlGenerator = $urlGenerator;
$this->embedFinderFactory = $embedFinderFactory;
}

/**
Expand Down Expand Up @@ -118,12 +109,6 @@ public function indexAction(Request $request): JsonResponse
);
}

/**
* Get a Node list from an array of id.
*
* @param Request $request
* @return JsonResponse
*/
public function listAction(Request $request): JsonResponse
{
if (!$request->query->has('nodeTypeFieldId')) {
Expand Down
5 changes: 1 addition & 4 deletions src/AjaxControllers/AjaxExplorerProviderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@

class AjaxExplorerProviderController extends AbstractAjaxController
{
private ContainerInterface $psrContainer;

public function __construct(ContainerInterface $psrContainer)
public function __construct(private readonly ContainerInterface $psrContainer)
{
$this->psrContainer = $psrContainer;
}

/**
Expand Down
20 changes: 5 additions & 15 deletions src/AjaxControllers/AjaxFolderTreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,14 @@

class AjaxFolderTreeController extends AbstractAjaxController
{
private TreeWidgetFactory $treeWidgetFactory;

public function __construct(TreeWidgetFactory $treeWidgetFactory)
public function __construct(private readonly TreeWidgetFactory $treeWidgetFactory)
{
$this->treeWidgetFactory = $treeWidgetFactory;
}

/**
* @param Request $request
*
* @return JsonResponse
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function getTreeAction(Request $request)
public function getTreeAction(Request $request): JsonResponse
{
$this->denyAccessUnlessGranted('ROLE_ACCESS_DOCUMENTS');
$translation = $this->getTranslation($request);

/** @var FolderTreeWidget|null $folderTree */
$folderTree = null;
Expand All @@ -49,7 +39,7 @@ public function getTreeAction(Request $request)
$folder = null;
}

$folderTree = $this->treeWidgetFactory->createFolderTree($folder);
$folderTree = $this->treeWidgetFactory->createFolderTree($folder, $translation);

$this->assignation['mainFolderTree'] = false;

Expand All @@ -59,7 +49,7 @@ public function getTreeAction(Request $request)
*/
case 'requestMainFolderTree':
$parent = null;
$folderTree = $this->treeWidgetFactory->createFolderTree($parent);
$folderTree = $this->treeWidgetFactory->createFolderTree($parent, $translation);
$this->assignation['mainFolderTree'] = true;
break;
}
Expand Down
22 changes: 5 additions & 17 deletions src/AjaxControllers/AjaxFoldersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,15 @@

class AjaxFoldersController extends AbstractAjaxController
{
private HandlerFactoryInterface $handlerFactory;

public function __construct(HandlerFactoryInterface $handlerFactory)
public function __construct(private readonly HandlerFactoryInterface $handlerFactory)
{
$this->handlerFactory = $handlerFactory;
}

/**
/*
* Handle AJAX edition requests for Folder
* such as coming from tag-tree widgets.
*
* @param Request $request
* @param int $folderId
*
* @return Response JSON response
*/
public function editAction(Request $request, int $folderId)
public function editAction(Request $request, int $folderId): JsonResponse
{
$this->validateRequest($request);
$this->denyAccessUnlessGranted('ROLE_ACCESS_DOCUMENTS');
Expand Down Expand Up @@ -81,7 +73,7 @@ public function editAction(Request $request, int $folderId)
* @param Request $request
* @return JsonResponse
*/
public function searchAction(Request $request)
public function searchAction(Request $request): JsonResponse
{
$this->denyAccessUnlessGranted('ROLE_ACCESS_DOCUMENTS');

Expand Down Expand Up @@ -111,11 +103,7 @@ public function searchAction(Request $request)
throw $this->createNotFoundException($this->getTranslator()->trans('no.folder.found'));
}

/**
* @param array $parameters
* @param Folder $folder
*/
protected function updatePosition($parameters, Folder $folder): void
protected function updatePosition(array $parameters, Folder $folder): void
{
/*
* First, we set the new parent
Expand Down
7 changes: 1 addition & 6 deletions src/AjaxControllers/AjaxFoldersExplorerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@

class AjaxFoldersExplorerController extends AbstractAjaxController
{
/**
* @param Request $request
*
* @return Response JSON response
*/
public function indexAction(Request $request)
public function indexAction(Request $request): JsonResponse
{
$this->denyAccessUnlessGranted('ROLE_ACCESS_DOCUMENTS');

Expand Down
38 changes: 5 additions & 33 deletions src/AjaxControllers/AjaxNodeTreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,29 @@

namespace Themes\Rozier\AjaxControllers;

use RZ\Roadiz\CoreBundle\Security\Authorization\Chroot\NodeChrootResolver;
use RZ\Roadiz\CoreBundle\Bag\NodeTypes;
use RZ\Roadiz\CoreBundle\Entity\Node;
use RZ\Roadiz\CoreBundle\Entity\NodeType;
use RZ\Roadiz\CoreBundle\Entity\Tag;
use RZ\Roadiz\CoreBundle\Entity\Translation;
use RZ\Roadiz\CoreBundle\Security\Authorization\Chroot\NodeChrootResolver;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Themes\Rozier\Widgets\NodeTreeWidget;
use Themes\Rozier\Widgets\TreeWidgetFactory;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;

class AjaxNodeTreeController extends AbstractAjaxController
{
private NodeChrootResolver $nodeChrootResolver;
private TreeWidgetFactory $treeWidgetFactory;
private NodeTypes $nodeTypesBag;

public function __construct(
NodeChrootResolver $nodeChrootResolver,
TreeWidgetFactory $treeWidgetFactory,
NodeTypes $nodeTypesBag
private readonly NodeChrootResolver $nodeChrootResolver,
private readonly TreeWidgetFactory $treeWidgetFactory,
private readonly NodeTypes $nodeTypesBag
) {
$this->nodeChrootResolver = $nodeChrootResolver;
$this->treeWidgetFactory = $treeWidgetFactory;
$this->nodeTypesBag = $nodeTypesBag;
}

/**
* @param Request $request
*
* @return JsonResponse
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getTreeAction(Request $request): JsonResponse
{
$this->denyAccessUnlessGranted('ROLE_ACCESS_NODES');

$translationId = $request->get('translationId', null);
if (\is_numeric($translationId) && $translationId > 0) {
$translation = $this->em()->find(
Translation::class,
$translationId
);
} else {
$translation = $this->em()->getRepository(Translation::class)->findDefault();
}
$translation = $this->getTranslation($request);

/** @var NodeTreeWidget|null $nodeTree */
$nodeTree = null;
Expand Down
Loading

0 comments on commit b287239

Please sign in to comment.