Skip to content

Commit

Permalink
TASK: Improve DI for TemplateNodeCreationHandler and early return i…
Browse files Browse the repository at this point in the history
…f `$$nodeType` does not exist like in v2
  • Loading branch information
mhsdesign committed Jun 22, 2024
1 parent 3f0bad4 commit f35a583
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
35 changes: 8 additions & 27 deletions Classes/Domain/TemplateNodeCreationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,19 @@
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindClosestNodeFilter;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\Service\NodeTypeNameFactory;
use Neos\Neos\Ui\Domain\NodeCreation\NodeCreationCommands;
use Neos\Neos\Ui\Domain\NodeCreation\NodeCreationElements;
use Neos\Neos\Ui\Domain\NodeCreation\NodeCreationHandlerInterface;

class TemplateNodeCreationHandler implements NodeCreationHandlerInterface
final readonly class TemplateNodeCreationHandler implements NodeCreationHandlerInterface
{
/**
* @var NodeCreationService
* @Flow\Inject
*/
protected $nodeCreationService;

/**
* @var TemplateConfigurationProcessor
* @Flow\Inject
*/
protected $templateConfigurationProcessor;

/**
* @var ProcessingErrorHandler
* @Flow\Inject
*/
protected $processingErrorHandler;

public function __construct(private readonly ContentRepository $contentRepository)
{
public function __construct(
private ContentRepository $contentRepository,
private NodeCreationService $nodeCreationService,
private TemplateConfigurationProcessor $templateConfigurationProcessor,
private ProcessingErrorHandler $processingErrorHandler
) {
}

/**
Expand All @@ -49,11 +34,7 @@ public function handle(
$nodeType = $this->contentRepository->getNodeTypeManager()
->getNodeType($commands->first->nodeTypeName);

if (!$nodeType) {
throw new \RuntimeException(sprintf('Initial NodeType "%s" does not exist anymore.', $commands->first->nodeTypeName->value), 1718950358);
}

$templateConfiguration = $nodeType->getOptions()['template'] ?? null;
$templateConfiguration = $nodeType?->getOptions()['template'] ?? null;
if (!$templateConfiguration) {
return $commands;
}
Expand Down
20 changes: 19 additions & 1 deletion Classes/Domain/TemplateNodeCreationHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,32 @@

namespace Flowpack\NodeTemplates\Domain;

use Flowpack\NodeTemplates\Domain\ErrorHandling\ProcessingErrorHandler;
use Flowpack\NodeTemplates\Domain\NodeCreation\NodeCreationService;
use Flowpack\NodeTemplates\Domain\TemplateConfiguration\TemplateConfigurationProcessor;
use Neos\ContentRepository\Core\ContentRepository;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Ui\Domain\NodeCreation\NodeCreationHandlerFactoryInterface;
use Neos\Neos\Ui\Domain\NodeCreation\NodeCreationHandlerInterface;

final class TemplateNodeCreationHandlerFactory implements NodeCreationHandlerFactoryInterface
{
#[Flow\Inject]
protected NodeCreationService $nodeCreationService;

#[Flow\Inject]
protected TemplateConfigurationProcessor $templateConfigurationProcessor;

#[Flow\Inject]
protected ProcessingErrorHandler $processingErrorHandler;

public function build(ContentRepository $contentRepository): NodeCreationHandlerInterface
{
return new TemplateNodeCreationHandler($contentRepository);
return new TemplateNodeCreationHandler(
$contentRepository,
$this->nodeCreationService,
$this->templateConfigurationProcessor,
$this->processingErrorHandler
);
}
}

0 comments on commit f35a583

Please sign in to comment.