Skip to content

Commit

Permalink
Merge branch feature/explorers-refactor into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Aug 28, 2024
1 parent 474c54b commit a6f8317
Show file tree
Hide file tree
Showing 45 changed files with 624 additions and 673 deletions.
13 changes: 6 additions & 7 deletions src/AjaxControllers/AjaxCustomFormsExplorerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
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\Routing\Generator\UrlGeneratorInterface;
use Themes\Rozier\Models\CustomFormModel;

final class AjaxCustomFormsExplorerController extends AbstractAjaxController
{
public function __construct(private readonly UrlGeneratorInterface $urlGenerator)
{
public function __construct(
private readonly ExplorerItemFactoryInterface $explorerItemFactory,
) {
}

/**
Expand Down Expand Up @@ -104,16 +104,15 @@ public function listAction(Request $request): Response
/**
* Normalize response CustomForm list result.
*
* @param array<CustomForm>|\Traversable<CustomForm> $customForms
* @param iterable<CustomForm> $customForms
* @return array
*/
private function normalizeCustomForms(iterable $customForms): array
{
$customFormsArray = [];

/** @var CustomForm $customForm */
foreach ($customForms as $customForm) {
$customFormModel = new CustomFormModel($customForm, $this->urlGenerator, $this->getTranslator());
$customFormModel = $this->explorerItemFactory->createForEntity($customForm);
$customFormsArray[] = $customFormModel->toArray();
}

Expand Down
32 changes: 7 additions & 25 deletions src/AjaxControllers/AjaxDocumentsExplorerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,18 @@

use RZ\Roadiz\CoreBundle\Entity\Document;
use RZ\Roadiz\CoreBundle\Entity\Folder;
use RZ\Roadiz\Documents\MediaFinders\EmbedFinderFactory;
use RZ\Roadiz\Documents\Renderer\RendererInterface;
use RZ\Roadiz\Documents\UrlGenerators\DocumentUrlGeneratorInterface;
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\Routing\Generator\UrlGeneratorInterface;
use Themes\Rozier\Models\DocumentModel;

final class AjaxDocumentsExplorerController extends AbstractAjaxController
{
public function __construct(
private readonly RendererInterface $renderer,
private readonly DocumentUrlGeneratorInterface $documentUrlGenerator,
private readonly UrlGeneratorInterface $urlGenerator,
private readonly EmbedFinderFactory $embedFinderFactory
private readonly ExplorerItemFactoryInterface $explorerItemFactory
) {
}

public static array $thumbnailArray = [
"fit" => "40x40",
"quality" => 50,
"inline" => false,
];

public function indexAction(Request $request): JsonResponse
{
$this->denyAccessUnlessGranted('ROLE_ACCESS_DOCUMENTS');
Expand Down Expand Up @@ -61,7 +48,8 @@ public function indexAction(Request $request): JsonResponse
]
);
$listManager->setDisplayingNotPublishedNodes(true);
$listManager->setItemPerPage(30);
// Use a factor of 12 for a better grid display
$listManager->setItemPerPage(36);
$listManager->handle();

$documents = $listManager->getEntities();
Expand Down Expand Up @@ -131,21 +119,15 @@ public function listAction(Request $request): JsonResponse
/**
* Normalize response Document list result.
*
* @param array<Document> $documents
* @param iterable<Document> $documents
* @return array
*/
private function normalizeDocuments(array $documents): array
private function normalizeDocuments(iterable $documents): array
{
$documentsArray = [];

foreach ($documents as $doc) {
$documentModel = new DocumentModel(
$doc,
$this->renderer,
$this->documentUrlGenerator,
$this->urlGenerator,
$this->embedFinderFactory
);
$documentModel = $this->explorerItemFactory->createForEntity($doc);
$documentsArray[] = $documentModel->toArray();
}

Expand Down
38 changes: 6 additions & 32 deletions src/AjaxControllers/AjaxEntitiesExplorerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,18 @@
use RZ\Roadiz\Core\AbstractEntities\AbstractField;
use RZ\Roadiz\Core\AbstractEntities\PersistableInterface;
use RZ\Roadiz\CoreBundle\Configuration\JoinNodeTypeFieldConfiguration;
use RZ\Roadiz\CoreBundle\Entity\Folder;
use RZ\Roadiz\CoreBundle\Entity\NodeTypeField;
use RZ\Roadiz\CoreBundle\Entity\Setting;
use RZ\Roadiz\CoreBundle\Entity\User;
use RZ\Roadiz\Documents\MediaFinders\EmbedFinderFactory;
use RZ\Roadiz\Documents\Renderer\RendererInterface;
use RZ\Roadiz\Documents\UrlGenerators\DocumentUrlGeneratorInterface;
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\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Yaml\Yaml;
use Themes\Rozier\Explorer\ConfigurableExplorerItem;
use Themes\Rozier\Explorer\FolderExplorerItem;
use Themes\Rozier\Explorer\SettingExplorerItem;
use Themes\Rozier\Explorer\UserExplorerItem;

final class AjaxEntitiesExplorerController extends AbstractAjaxController
{
public function __construct(
private readonly RendererInterface $renderer,
private readonly DocumentUrlGeneratorInterface $documentUrlGenerator,
private readonly UrlGeneratorInterface $urlGenerator,
private readonly EmbedFinderFactory $embedFinderFactory
private readonly ExplorerItemFactoryInterface $explorerItemFactory,
) {
}

Expand Down Expand Up @@ -177,24 +164,11 @@ private function normalizeEntities(iterable $entities, array $configuration): ar
{
$entitiesArray = [];

/** @var PersistableInterface $entity */
foreach ($entities as $entity) {
if ($entity instanceof Folder) {
$explorerItem = new FolderExplorerItem($entity, $this->urlGenerator);
} elseif ($entity instanceof Setting) {
$explorerItem = new SettingExplorerItem($entity, $this->urlGenerator);
} elseif ($entity instanceof User) {
$explorerItem = new UserExplorerItem($entity, $this->urlGenerator);
} else {
$explorerItem = new ConfigurableExplorerItem(
$entity,
$configuration,
$this->renderer,
$this->documentUrlGenerator,
$this->urlGenerator,
$this->embedFinderFactory
);
}
$explorerItem = $this->explorerItemFactory->createForEntity(
$entity,
$configuration
);
$entitiesArray[] = $explorerItem->toArray();
}

Expand Down
8 changes: 1 addition & 7 deletions src/AjaxControllers/AjaxExplorerProviderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use RZ\Roadiz\CoreBundle\Explorer\AbstractExplorerProvider;
use RZ\Roadiz\CoreBundle\Explorer\ExplorerItemInterface;
use RZ\Roadiz\CoreBundle\Explorer\ExplorerProviderInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand Down Expand Up @@ -56,12 +55,7 @@ protected function getProviderFromRequest(Request $request): ExplorerProviderInt
throw new InvalidParameterException('providerClass is not a valid ExplorerProviderInterface class.');
}

$provider = $this->getProvider($providerClass);
if ($provider instanceof AbstractExplorerProvider) {
$provider->setContainer($this->psrContainer);
}

return $provider;
return $this->getProvider($providerClass);
}

/**
Expand Down
12 changes: 8 additions & 4 deletions src/AjaxControllers/AjaxNodeTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Exception\NotSupported;
use RZ\Roadiz\CoreBundle\Entity\NodeType;
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 Themes\Rozier\Models\NodeTypeModel;

final class AjaxNodeTypesController extends AbstractAjaxController
{
public function __construct(
private readonly ExplorerItemFactoryInterface $explorerItemFactory
) {
}

/**
* @param Request $request
*
Expand Down Expand Up @@ -97,16 +102,15 @@ public function listAction(Request $request): Response
/**
* Normalize response NodeType list result.
*
* @param array<NodeType>|\Traversable<NodeType> $nodeTypes
* @param iterable<NodeType> $nodeTypes
* @return array
*/
private function normalizeNodeType(iterable $nodeTypes): array
{
$nodeTypesArray = [];

/** @var NodeType $nodeType */
foreach ($nodeTypes as $nodeType) {
$nodeModel = new NodeTypeModel($nodeType);
$nodeModel = $this->explorerItemFactory->createForEntity($nodeType);
$nodeTypesArray[] = $nodeModel->toArray();
}

Expand Down
20 changes: 7 additions & 13 deletions src/AjaxControllers/AjaxNodesExplorerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use RZ\Roadiz\CoreBundle\Entity\NodesSources;
use RZ\Roadiz\CoreBundle\Entity\Tag;
use RZ\Roadiz\CoreBundle\EntityApi\NodeTypeApi;
use RZ\Roadiz\CoreBundle\Explorer\AbstractExplorerItem;
use RZ\Roadiz\CoreBundle\Explorer\ExplorerItemFactoryInterface;
use RZ\Roadiz\CoreBundle\SearchEngine\ClientRegistry;
use RZ\Roadiz\CoreBundle\SearchEngine\NodeSourceSearchHandlerInterface;
use RZ\Roadiz\CoreBundle\SearchEngine\SolrSearchResultItem;
Expand All @@ -20,20 +22,15 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Exception\InvalidParameterException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Bundle\SecurityBundle\Security;
use Themes\Rozier\Models\NodeModel;
use Themes\Rozier\Models\NodeSourceModel;

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,
private readonly UrlGeneratorInterface $urlGenerator,
private readonly Security $security,
) {
}

Expand Down Expand Up @@ -251,7 +248,7 @@ public function listAction(Request $request): JsonResponse
* Normalize response Node list result.
*
* @param iterable<Node|NodesSources|SolrSearchResultItem> $nodes
* @return array
* @return array<AbstractExplorerItem>
*/
private function normalizeNodes(iterable $nodes): array
{
Expand All @@ -273,12 +270,9 @@ private function normalizeNodes(iterable $nodes): array

private function normalizeItem(NodesSources|Node $item, array &$nodesArray): void
{
if ($item instanceof NodesSources && !key_exists($item->getNode()->getId(), $nodesArray)) {
$nodeSourceModel = new NodeSourceModel($item, $this->urlGenerator, $this->security);
$nodesArray[$item->getNode()->getId()] = $nodeSourceModel->toArray();
} elseif ($item instanceof Node && !key_exists($item->getId(), $nodesArray)) {
$nodeModel = new NodeModel($item, $this->urlGenerator, $this->security);
$nodesArray[$item->getId()] = $nodeModel->toArray();
$model = $this->explorerItemFactory->createForEntity($item);
if (!key_exists($model->getId(), $nodesArray)) {
$nodesArray[$model->getId()] = $model->toArray();
}
}

Expand Down
15 changes: 7 additions & 8 deletions src/AjaxControllers/AjaxTagsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,25 @@

use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use RZ\Roadiz\Core\Handlers\HandlerFactoryInterface;
use RZ\Roadiz\CoreBundle\Entity\Tag;
use RZ\Roadiz\CoreBundle\Entity\Translation;
use RZ\Roadiz\CoreBundle\Event\Tag\TagUpdatedEvent;
use RZ\Roadiz\Core\Handlers\HandlerFactoryInterface;
use RZ\Roadiz\CoreBundle\EntityHandler\TagHandler;
use RZ\Roadiz\CoreBundle\Event\Tag\TagUpdatedEvent;
use RZ\Roadiz\CoreBundle\Explorer\ExplorerItemFactoryInterface;
use RZ\Roadiz\CoreBundle\Repository\TagRepository;
use RZ\Roadiz\Utils\StringHandler;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Exception\InvalidParameterException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Themes\Rozier\Models\TagModel;

final class AjaxTagsController extends AbstractAjaxController
{
public function __construct(
private readonly HandlerFactoryInterface $handlerFactory,
private readonly UrlGeneratorInterface $urlGenerator
private readonly ExplorerItemFactoryInterface $explorerItemFactory,
private readonly HandlerFactoryInterface $handlerFactory
) {
}

Expand Down Expand Up @@ -176,7 +175,7 @@ protected function normalizeTags($tags): array
$tagsArray = [];
if ($tags !== null) {
foreach ($tags as $tag) {
$tagModel = new TagModel($tag, $this->urlGenerator);
$tagModel = $this->explorerItemFactory->createForEntity($tag);
$tagsArray[] = $tagModel->toArray();
}
}
Expand Down Expand Up @@ -368,7 +367,7 @@ public function createAction(Request $request): JsonResponse

/** @var Tag $tag */
$tag = $this->getRepository()->findOrCreateByPath($request->get('tagName'));
$tagModel = new TagModel($tag, $this->urlGenerator);
$tagModel = $this->explorerItemFactory->createForEntity($tag);

return new JsonResponse(
[
Expand Down
Loading

0 comments on commit a6f8317

Please sign in to comment.