Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK: Adjust to Node:$nodeType removal #3784

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions Classes/Domain/Model/AbstractChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* source code.
*/

use Neos\ContentRepository\Core\NodeType\NodeType;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindClosestNodeFilter;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
Expand All @@ -21,15 +22,12 @@
use Neos\Neos\Ui\Domain\Model\Feedback\Operations\NodeCreated;
use Neos\Neos\Ui\Domain\Model\Feedback\Operations\ReloadDocument;
use Neos\Neos\Ui\Domain\Model\Feedback\Operations\UpdateWorkspaceInfo;
use Neos\Neos\Utility\NodeTypeWithFallbackProvider;

/**
* @internal
*/
abstract class AbstractChange implements ChangeInterface
{
use NodeTypeWithFallbackProvider;

protected ?Node $subject = null;

#[Flow\Inject]
Expand All @@ -53,20 +51,20 @@ abstract class AbstractChange implements ChangeInterface
*/
protected $persistenceManager;

public function setSubject(Node $subject): void
final public function setSubject(Node $subject): void
{
$this->subject = $subject;
}

public function getSubject(): ?Node
final public function getSubject(): ?Node
{
return $this->subject;
}

/**
* Helper method to inform the client, that new workspace information is available
*/
protected function updateWorkspaceInfo(): void
final protected function updateWorkspaceInfo(): void
{
if (!is_null($this->subject)) {
$subgraph = $this->contentRepositoryRegistry->subgraphForNode($this->subject);
Expand All @@ -78,12 +76,18 @@ protected function updateWorkspaceInfo(): void
}
}

protected function findParentNode(Node $node): ?Node
final protected function findParentNode(Node $node): ?Node
{
return $this->contentRepositoryRegistry->subgraphForNode($node)
->findParentNode($node->aggregateId);
}

final protected function getNodeType(Node $node): ?NodeType
{
$contentRepository = $this->contentRepositoryRegistry->get($node->contentRepositoryId);
return $contentRepository->getNodeTypeManager()->getNodeType($node->nodeTypeName);
}

/**
* Inform the client to reload the currently-displayed document, because the rendering has changed.
*
Expand All @@ -102,7 +106,7 @@ protected function reloadDocument(Node $node = null): void
/**
* Inform the client that a node has been created, the client decides if and which tree should react to this change.
*/
protected function addNodeCreatedFeedback(Node $subject = null): void
final protected function addNodeCreatedFeedback(Node $subject = null): void
{
$node = $subject ?: $this->getSubject();
if ($node) {
Expand Down
18 changes: 11 additions & 7 deletions Classes/Domain/Model/Changes/AbstractCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@

use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryInterface;
use Neos\ContentRepository\Core\Feature\NodeCreation\Command\CreateNodeAggregateWithNode;
use Neos\ContentRepository\Core\NodeType\NodeType;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\SharedModel\Exception\NodeNameIsAlreadyOccupied;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\Flow\Annotations as Flow;
Expand Down Expand Up @@ -134,13 +133,19 @@ protected function createNode(
if (is_null($nodeTypeName)) {
throw new \RuntimeException('Cannot run createNode without a set node type.', 1645577794);
}

$contentRepository = $this->contentRepositoryRegistry->get($parentNode->contentRepositoryId);
$nodeType = $contentRepository->getNodeTypeManager()->getNodeType($nodeTypeName);
if (is_null($nodeType)) {
throw new \RuntimeException(sprintf('Cannot run create node because the node type %s is missing.', $nodeTypeName->value), 1716019747);
}

$nodeName = $this->getName()
? NodeName::fromString($this->getName())
: null;

$nodeAggregateId = $this->getNodeAggregateId() ?? NodeAggregateId::create(); // generate a new NodeAggregateId

$contentRepository = $this->contentRepositoryRegistry->get($parentNode->contentRepositoryId);

$command = CreateNodeAggregateWithNode::create(
$parentNode->workspaceName,
Expand All @@ -158,10 +163,10 @@ protected function createNode(
$contentRepository->getNodeTypeManager()
),
$this->nodePropertyConversionService->convertNodeCreationElements(
$contentRepository->getNodeTypeManager()->getNodeType($nodeTypeName),
$nodeType,
$this->getData() ?: []
),
$nodeTypeName,
$nodeType,
$contentRepository
);

Expand Down Expand Up @@ -189,10 +194,9 @@ protected function createNode(
protected function applyNodeCreationHandlers(
NodeCreationCommands $commands,
NodeCreationElements $elements,
NodeTypeName $nodeTypeName,
NodeType $nodeType,
ContentRepository $contentRepository
): NodeCreationCommands {
$nodeType = $contentRepository->getNodeTypeManager()->getNodeType($nodeTypeName);
if (!isset($nodeType->getOptions()['nodeCreationHandlers'])
|| !is_array($nodeType->getOptions()['nodeCreationHandlers'])) {
return $commands;
Expand Down
11 changes: 2 additions & 9 deletions Classes/Domain/Model/Changes/AbstractStructuralChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\Nodes;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateClassification;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\FrontendRouting\NodeAddressFactory;
use Neos\Neos\Ui\ContentRepository\Service\NeosUiNodeService;
Expand All @@ -26,7 +25,6 @@
use Neos\Neos\Ui\Domain\Model\Feedback\Operations\RenderContentOutOfBand;
use Neos\Neos\Ui\Domain\Model\Feedback\Operations\UpdateNodeInfo;
use Neos\Neos\Ui\Domain\Model\RenderedNodeDomAddress;
use Neos\Neos\Utility\NodeTypeWithFallbackProvider;

/**
* A change that performs structural actions like moving or creating nodes
Expand All @@ -36,11 +34,6 @@
*/
abstract class AbstractStructuralChange extends AbstractChange
{
use NodeTypeWithFallbackProvider;

#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

/**
* The node dom address for the parent node of the created node
*/
Expand Down Expand Up @@ -149,14 +142,14 @@ protected function finish(Node $node)

$this->updateWorkspaceInfo();

if ($this->getNodeType($node)->isOfType('Neos.Neos:Content')
if ($this->getNodeType($node)?->isOfType('Neos.Neos:Content')
&& ($this->getParentDomAddress() || $this->getSiblingDomAddress())) {
// we can ONLY render out of band if:
// 1) the parent of our new (or copied or moved) node is a ContentCollection;
// so we can directly update an element of this content collection

$contentRepository = $this->contentRepositoryRegistry->get($node->contentRepositoryId);
if ($parentNode && $this->getNodeType($parentNode)->isOfType('Neos.Neos:ContentCollection') &&
if ($parentNode && $this->getNodeType($parentNode)?->isOfType('Neos.Neos:ContentCollection') &&
// 2) the parent DOM address (i.e. the closest RENDERED node in DOM is actually the ContentCollection;
// and no other node in between
$this->getParentDomAddress() &&
Expand Down
81 changes: 37 additions & 44 deletions Classes/Domain/Model/Changes/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@
use Neos\ContentRepository\Core\Feature\NodeTypeChange\Command\ChangeNodeAggregateType;
use Neos\ContentRepository\Core\Feature\NodeTypeChange\Dto\NodeAggregateTypeChangeChildConstraintConflictResolutionStrategy;
use Neos\ContentRepository\Core\Feature\NodeVariation\Command\CreateNodeVariant;
use Neos\ContentRepository\Core\NodeType\NodeType;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\SharedModel\Exception\ContentStreamDoesNotExistYet;
use Neos\ContentRepository\Core\SharedModel\Exception\NodeAggregatesTypeIsAmbiguous;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateIds;
use Neos\ContentRepository\Core\SharedModel\Node\NodeVariantSelectionStrategy;
use Neos\ContentRepository\Core\SharedModel\Node\ReferenceName;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Ui\Domain\Model\AbstractChange;
use Neos\Neos\Ui\Domain\Model\Feedback\Operations\ReloadContentOutOfBand;
use Neos\Neos\Ui\Domain\Model\Feedback\Operations\UpdateNodeInfo;
use Neos\Neos\Ui\Domain\Model\RenderedNodeDomAddress;
use Neos\Neos\Ui\Domain\Service\NodePropertyConversionService;
use Neos\Neos\Utility\NodeTypeWithFallbackProvider;

/**
* Changes a property on a node
Expand All @@ -47,11 +46,6 @@
*/
class Property extends AbstractChange
{
use NodeTypeWithFallbackProvider;

#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

/**
* @Flow\Inject
* @var NodePropertyConversionService
Expand Down Expand Up @@ -131,12 +125,14 @@ public function getIsInline(): bool
*/
public function canApply(): bool
{
if (is_null($this->subject) || is_null($this->subject->nodeType)) {
$propertyName = $this->getPropertyName();
if (!$this->subject || !$propertyName) {
return false;
}
$nodeType = $this->getNodeType($this->subject);
if (!$nodeType) {
return false;
}
$nodeType = $this->subject->nodeType;
$propertyName = $this->getPropertyName();

return $nodeType->hasProperty($propertyName) || $nodeType->hasReference($propertyName);
}

Expand All @@ -151,18 +147,19 @@ public function canApply(): bool
public function apply(): void
{
$subject = $this->subject;
$nodeType = $subject ? $this->getNodeType($subject) : null;
$propertyName = $this->getPropertyName();
if (is_null($subject) || is_null($propertyName) || $this->canApply() === false) {
if (is_null($subject) || is_null($nodeType) || is_null($propertyName) || $this->canApply() === false) {
return;
}

match (true) {
$this->getNodeType($subject)->hasReference($propertyName) => $this->handleNodeReferenceChange($subject, $propertyName),
$nodeType->hasReference($propertyName) => $this->handleNodeReferenceChange($subject, $propertyName),
// todo create custom 'changes' for these special cases
// we continue to use the underscore logic in the Neos Ui code base as the JS-client code works this way
$propertyName === '_nodeType' => $this->handleNodeTypeChange($subject, $propertyName),
$propertyName === '_hidden' => $this->handleHiddenPropertyChange($subject, $propertyName),
default => $this->handlePropertyChange($subject, $propertyName)
$propertyName === '_nodeType' => $this->handleNodeTypeChange($subject),
$propertyName === '_hidden' => $this->handleHiddenPropertyChange($subject),
default => $this->handlePropertyChange($subject, $nodeType, $propertyName)
};

$this->createFeedback($subject);
Expand Down Expand Up @@ -197,13 +194,13 @@ private function createFeedback(Node $subject): void
$reloadIfChangedConfigurationPathForReference = sprintf('references.%s.ui.reloadIfChanged', $propertyName);
if (!$this->getIsInline()
&& (
$this->getNodeType($node)->getConfiguration($reloadIfChangedConfigurationPathForProperty)
|| $this->getNodeType($node)->getConfiguration($reloadIfChangedConfigurationPathForReference)
$this->getNodeType($node)?->getConfiguration($reloadIfChangedConfigurationPathForProperty)
|| $this->getNodeType($node)?->getConfiguration($reloadIfChangedConfigurationPathForReference)
)
) {
if ($this->getNodeDomAddress() && $this->getNodeDomAddress()->getFusionPath()
&& $parentNode
&& $this->getNodeType($parentNode)->isOfType('Neos.Neos:ContentCollection')) {
&& $this->getNodeType($parentNode)?->isOfType('Neos.Neos:ContentCollection')) {
$reloadContentOutOfBand = new ReloadContentOutOfBand();
$reloadContentOutOfBand->setNode($node);
$reloadContentOutOfBand->setNodeDomAddress($this->getNodeDomAddress());
Expand All @@ -217,8 +214,8 @@ private function createFeedback(Node $subject): void
$reloadPageIfChangedConfigurationPathForReference = sprintf('references.%s.ui.reloadPageIfChanged', $propertyName);
if (!$this->getIsInline()
&& (
$this->getNodeType($node)->getConfiguration($reloadPageIfChangedConfigurationPathForProperty)
|| $this->getNodeType($node)->getConfiguration($reloadPageIfChangedConfigurationPathForReference)
$this->getNodeType($node)?->getConfiguration($reloadPageIfChangedConfigurationPathForProperty)
|| $this->getNodeType($node)?->getConfiguration($reloadPageIfChangedConfigurationPathForReference)
)
) {
$this->reloadDocument($node);
Expand Down Expand Up @@ -248,41 +245,37 @@ private function handleNodeReferenceChange(Node $subject, string $propertyName):
);
}

private function handleHiddenPropertyChange(Node $subject, string $propertyName): void
private function handleHiddenPropertyChange(Node $subject): void
{
$value = $this->nodePropertyConversionService->convert(
$this->getNodeType($subject)->getPropertyType($propertyName),
$this->getValue()
);
// todo simplify conversion
$value = (bool)$this->nodePropertyConversionService->convert('boolean', $this->getValue());

$contentRepository = $this->contentRepositoryRegistry->get($subject->contentRepositoryId);

$command = EnableNodeAggregate::create(
$subject->workspaceName,
$subject->aggregateId,
$subject->originDimensionSpacePoint->toDimensionSpacePoint(),
NodeVariantSelectionStrategy::STRATEGY_ALL_SPECIALIZATIONS
);

if ($value === true) {
$command = DisableNodeAggregate::create(
$command = match ($value) {
false => EnableNodeAggregate::create(
$subject->workspaceName,
$subject->aggregateId,
$subject->originDimensionSpacePoint->toDimensionSpacePoint(),
NodeVariantSelectionStrategy::STRATEGY_ALL_SPECIALIZATIONS
);
}
),
true => DisableNodeAggregate::create(
$subject->workspaceName,
$subject->aggregateId,
$subject->originDimensionSpacePoint->toDimensionSpacePoint(),
NodeVariantSelectionStrategy::STRATEGY_ALL_SPECIALIZATIONS
)
};

$contentRepository->handle($command);
}

private function handleNodeTypeChange(Node $subject, string $propertyName): void
private function handleNodeTypeChange(Node $subject): void
{
$contentRepository = $this->contentRepositoryRegistry->get($subject->contentRepositoryId);
$value = $this->nodePropertyConversionService->convert(
$this->getNodeType($subject)->getPropertyType($propertyName),
$this->getValue()
);
// todo simplify conversion
/** @var string $value */
$value = $this->nodePropertyConversionService->convert('string', $this->getValue());

$contentRepository->handle(
ChangeNodeAggregateType::create(
Expand All @@ -294,11 +287,11 @@ private function handleNodeTypeChange(Node $subject, string $propertyName): void
);
}

private function handlePropertyChange(Node $subject, string $propertyName): void
private function handlePropertyChange(Node $subject, NodeType $nodeType, string $propertyName): void
{
$contentRepository = $this->contentRepositoryRegistry->get($subject->contentRepositoryId);
$value = $this->nodePropertyConversionService->convert(
$this->getNodeType($subject)->getPropertyType($propertyName),
$nodeType->getPropertyType($propertyName),
$this->getValue()
);

Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/Changes/Remove.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private function getRemovalAttachmentPoint(): ?NodeAggregateId
{
$subgraph = $this->contentRepositoryRegistry->subgraphForNode($this->subject);

if ($this->subject->nodeType?->isOfType(NodeTypeNameFactory::NAME_DOCUMENT)) {
if ($this->getNodeType($this->subject)?->isOfType(NodeTypeNameFactory::NAME_DOCUMENT)) {
$closestSiteNode = $subgraph->findClosestNode($this->subject->aggregateId, FindClosestNodeFilter::create(nodeTypes: NodeTypeNameFactory::NAME_SITE));
return $closestSiteNode?->aggregateId;
}
Expand Down
6 changes: 2 additions & 4 deletions Classes/Domain/Model/Feedback/Operations/NodeCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@
use Neos\Neos\Domain\Service\NodeTypeNameFactory;
use Neos\Neos\Ui\Domain\Model\AbstractFeedback;
use Neos\Neos\Ui\Domain\Model\FeedbackInterface;
use Neos\Neos\Utility\NodeTypeWithFallbackProvider;

/**
* @internal
*/
class NodeCreated extends AbstractFeedback
{
use NodeTypeWithFallbackProvider;

#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

Expand Down Expand Up @@ -93,11 +90,12 @@ public function serializePayload(ControllerContext $controllerContext)
{
$node = $this->getNode();
$contentRepository = $this->contentRepositoryRegistry->get($node->contentRepositoryId);
$nodeType = $contentRepository->getNodeTypeManager()->getNodeType($node->nodeTypeName);
$nodeAddressFactory = NodeAddressFactory::create($contentRepository);
return [
'contextPath' => $nodeAddressFactory->createFromNode($node)->serializeForUri(),
'identifier' => $node->aggregateId->value,
'isDocument' => $this->getNodeType($node)->isOfType(NodeTypeNameFactory::NAME_DOCUMENT)
'isDocument' => $nodeType?->isOfType(NodeTypeNameFactory::NAME_DOCUMENT)
];
}
}
Loading
Loading