Skip to content

Commit e09cdd1

Browse files
author
roadiz-ci
committed
refactor: refactor all NodeType and NodesSources class-name resolution and improve nodetypes:validate-files (#262)
1 parent c888f54 commit e09cdd1

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/Controller/Node/NodesSourcesController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace RZ\Roadiz\RozierBundle\Controller\Node;
66

77
use Doctrine\Persistence\ManagerRegistry;
8+
use RZ\Roadiz\Contracts\NodeType\NodeTypeClassLocatorInterface;
89
use RZ\Roadiz\Core\AbstractEntities\PersistableInterface;
910
use RZ\Roadiz\CoreBundle\Bag\DecoratedNodeTypes;
1011
use RZ\Roadiz\CoreBundle\Entity\Node;
@@ -60,6 +61,7 @@ public function __construct(
6061
private readonly AllStatusesNodesSourcesRepository $allStatusesNodesSourcesRepository,
6162
private readonly AllStatusesNodeRepository $allStatusesNodeRepository,
6263
private readonly TranslationRepository $translationRepository,
64+
private readonly NodeTypeClassLocatorInterface $nodeTypeClassLocator,
6365
private readonly ?string $customPublicScheme,
6466
private readonly ?string $customPreviewScheme,
6567
) {
@@ -129,7 +131,7 @@ public function editSourceAction(Request $request, int $nodeId, int $translation
129131
NodeSourceType::class,
130132
$source,
131133
[
132-
'class' => $nodeType->getSourceEntityFullQualifiedClassName(),
134+
'class' => $this->nodeTypeClassLocator->getSourceEntityFullQualifiedClassName($nodeType),
133135
'nodeType' => $nodeType,
134136
'withVirtual' => true,
135137
'withTitle' => true,

src/Controller/NodeType/NodeTypeExportController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace RZ\Roadiz\RozierBundle\Controller\NodeType;
66

7+
use RZ\Roadiz\Contracts\NodeType\NodeTypeClassLocatorInterface;
78
use RZ\Roadiz\CoreBundle\Bag\DecoratedNodeTypes;
89
use RZ\Roadiz\Documentation\Generators\DocumentationGenerator;
910
use RZ\Roadiz\Typescript\Declaration\DeclarationGeneratorFactory;
@@ -23,6 +24,7 @@ final class NodeTypeExportController extends AbstractController
2324
public function __construct(
2425
private readonly DecoratedNodeTypes $nodeTypesBag,
2526
private readonly TranslatorInterface $translator,
27+
private readonly NodeTypeClassLocatorInterface $nodeTypeClassLocator,
2628
) {
2729
}
2830

@@ -79,7 +81,8 @@ public function exportTypeScriptDeclarationAction(Request $request): Response
7981
$this->denyAccessUnlessGranted('ROLE_ACCESS_NODETYPES');
8082

8183
$documentationGenerator = new DeclarationGenerator(
82-
new DeclarationGeneratorFactory($this->nodeTypesBag)
84+
new DeclarationGeneratorFactory($this->nodeTypesBag, $this->nodeTypeClassLocator),
85+
$this->nodeTypeClassLocator
8386
);
8487

8588
$fileName = 'roadiz-app-'.date('Ymd-His').'.d.ts';

src/Controller/SearchController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
namespace RZ\Roadiz\RozierBundle\Controller;
66

77
use Doctrine\Persistence\ManagerRegistry;
8+
use RZ\Roadiz\Contracts\NodeType\NodeTypeClassLocatorInterface;
89
use RZ\Roadiz\Core\Handlers\HandlerFactoryInterface;
910
use RZ\Roadiz\CoreBundle\Bag\NodeTypes;
1011
use RZ\Roadiz\CoreBundle\Entity\Node;
12+
use RZ\Roadiz\CoreBundle\Entity\NodesSources;
1113
use RZ\Roadiz\CoreBundle\Entity\NodeType;
1214
use RZ\Roadiz\CoreBundle\Entity\NodeTypeField;
1315
use RZ\Roadiz\CoreBundle\Entity\Tag;
@@ -63,6 +65,7 @@ public function __construct(
6365
private readonly Registry $workflowRegistry,
6466
private readonly EntityListManagerFactoryInterface $entityListManagerFactory,
6567
private readonly AllStatusesNodeRepository $allStatusesNodeRepository,
68+
private readonly NodeTypeClassLocatorInterface $nodeTypeClassLocator,
6669
private readonly array $csvEncoderOptions,
6770
) {
6871
}
@@ -415,9 +418,11 @@ protected function handleNodeForm(
415418
}
416419
$data = $this->processCriteria($data, $pagination, $itemPerPage, 'node.');
417420
$data = $this->processCriteriaNodeType($data, $nodeType);
421+
/** @var class-string<NodesSources> $entityClassName */
422+
$entityClassName = $this->nodeTypeClassLocator->getSourceEntityFullQualifiedClassName($nodeType);
418423

419424
$listManager = $this->entityListManagerFactory->createEntityListManager(
420-
$nodeType->getSourceEntityFullQualifiedClassName(),
425+
$entityClassName,
421426
$data
422427
);
423428
$listManager->setDisplayingNotPublishedNodes(true);

0 commit comments

Comments
 (0)