Skip to content

Commit

Permalink
Revert "Revert "Adjust to Neos 9 beta 10+""
Browse files Browse the repository at this point in the history
This reverts commit 2d55ade.
  • Loading branch information
Bernhard Schmitt committed Jun 9, 2024
1 parent 2d55ade commit 96468a0
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 162 deletions.
40 changes: 20 additions & 20 deletions Classes/Application/CacheTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

namespace Nezaniel\ComponentView\Application;

use Neos\ContentRepository\Core\Factory\ContentRepositoryId;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\Flow\Annotations as Flow;

/**
Expand All @@ -30,79 +30,79 @@ private function __construct(

final public static function forEverything(
?ContentRepositoryId $contentRepositoryId,
?ContentStreamId $contentStreamId,
?WorkspaceName $workspaceName,
): self {
return new self(
'Everything'
. self::renderContentRepositoryPrefix($contentRepositoryId)
. self::renderContentStreamPrefix($contentStreamId)
. self::renderWorkspacePrefix($workspaceName)
);
}

final public static function forNodeAggregate(
ContentRepositoryId $contentRepositoryId,
?ContentStreamId $contentStreamId,
?WorkspaceName $workspaceName,
NodeAggregateId $nodeAggregateId,
): self {
return new self(
'NodeAggregate'
. self::renderContentRepositoryPrefix($contentRepositoryId)
. self::renderContentStreamPrefix($contentStreamId)
. self::renderWorkspacePrefix($workspaceName)
. '_' . $nodeAggregateId->value
);
}

final public static function forNodeAggregateFromNode(Node $node): self
{
return self::forNodeAggregate(
$node->subgraphIdentity->contentRepositoryId,
$node->subgraphIdentity->contentStreamId,
$node->nodeAggregateId
$node->contentRepositoryId,
$node->workspaceName,
$node->aggregateId
);
}

final public static function forAncestorNode(
ContentRepositoryId $contentRepositoryId,
?ContentStreamId $contentStreamId,
?WorkspaceName $workspaceName,
NodeAggregateId $nodeAggregateId,
): self {
return new self(
'Ancestor'
. self::renderContentRepositoryPrefix($contentRepositoryId)
. self::renderContentStreamPrefix($contentStreamId)
. self::renderWorkspacePrefix($workspaceName)
. '_' . $nodeAggregateId->value
);
}

final public static function forAncestorNodeFromNode(Node $node): self
{
return self::forAncestorNode(
$node->subgraphIdentity->contentRepositoryId,
$node->subgraphIdentity->contentStreamId,
$node->nodeAggregateId
$node->contentRepositoryId,
$node->workspaceName,
$node->aggregateId
);
}

final public static function forNodeTypeName(
ContentRepositoryId $contentRepositoryId,
?ContentStreamId $contentStreamId,
?WorkspaceName $workspaceName,
NodeTypeName $nodeTypeName,
): self {
return new self(
'NodeType'
. self::renderContentRepositoryPrefix($contentRepositoryId)
. self::renderContentStreamPrefix($contentStreamId)
. self::renderWorkspacePrefix($workspaceName)
. '_' . \strtr($nodeTypeName->value, '.:', '_-')
);
}

final public static function forAsset(
string $assetIdentifier,
?ContentStreamId $contentStreamId = null,
?WorkspaceName $workspaceName = null,
): self {
return new self(
'Asset'
. self::renderContentStreamPrefix($contentStreamId)
. self::renderWorkspacePrefix($workspaceName)
. '_' . $assetIdentifier
);
}
Expand All @@ -119,9 +119,9 @@ final public static function fromString(string $string): self
return new self($string);
}

private static function renderContentStreamPrefix(?ContentStreamId $contentStreamId): string
private static function renderWorkspacePrefix(?WorkspaceName $workspaceName): string
{
return $contentStreamId ? '_%' . $contentStreamId->value . '%' : '';
return $workspaceName ? '_%' . $workspaceName->value . '%' : '';
}

private static function renderContentRepositoryPrefix(?ContentRepositoryId $contentRepositoryId): string
Expand Down
8 changes: 4 additions & 4 deletions Classes/Application/CacheTagSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

namespace Nezaniel\ComponentView\Application;

use Neos\ContentRepository\Core\Factory\ContentRepositoryId;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\NodeType\NodeTypeNames;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\Flow\Annotations as Flow;

/**
Expand All @@ -38,13 +38,13 @@ public function __construct(CacheTag ...$tags)

public static function forNodeTypeNames(
ContentRepositoryId $contentRepositoryId,
ContentStreamId $contentStreamId,
WorkspaceName $workspaceName,
NodeTypeNames $nodeTypeNames
): self {
return new self(...array_map(
fn (NodeTypeName $nodeTypeName): CacheTag => CacheTag::forNodeTypeName(
$contentRepositoryId,
$contentStreamId,
$workspaceName,
$nodeTypeName
),
iterator_to_array($nodeTypeNames)
Expand Down
32 changes: 20 additions & 12 deletions Classes/Application/ComponentView.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,25 @@
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\Controller\ControllerContext;
use Neos\Flow\Mvc\View\AbstractView;
use Neos\Http\Factories\StreamFactoryTrait;
use Neos\Neos\Domain\Model\RenderingMode;
use Neos\Neos\Domain\Service\NodeTypeNameFactory;
use Neos\Neos\Domain\Service\RenderingModeService;
use Neos\Neos\Ui\View\OutOfBandRenderingCapable;
use Nezaniel\ComponentView\Domain\RenderingEntryPoint;
use Nezaniel\ComponentView\Domain\UriService;
use Psr\Http\Message\StreamInterface;

/**
* A view that triggers creation of self-rendering components and lets them render themselves
*/
class ComponentView extends AbstractView implements OutOfBandRenderingCapable
{
use StreamFactoryTrait;

#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

Expand All @@ -42,6 +47,8 @@ class ComponentView extends AbstractView implements OutOfBandRenderingCapable

private ?RenderingEntryPoint $renderingEntryPoint = null;

private ?ActionRequest $actionRequest = null;

/**
* @var array<string,mixed>
*/
Expand All @@ -55,7 +62,7 @@ class ComponentView extends AbstractView implements OutOfBandRenderingCapable

public function setControllerContext(ControllerContext $controllerContext): void
{
$this->controllerContext = $controllerContext;
$this->actionRequest = $controllerContext->getRequest();
$this->uriService->setControllerContext($controllerContext);
}

Expand Down Expand Up @@ -91,30 +98,31 @@ public function canRender(ControllerContext $controllerContext): bool
return $this->documentNode instanceof Node;
}

public function render(): string
public function render(): StreamInterface
{
assert($this->documentNode instanceof Node);
$subgraph = $this->contentRepositoryRegistry->subgraphForNode($this->documentNode);
$siteNode = $this->findClosestSite($subgraph, $this->documentNode);
assert($siteNode instanceof Node);
assert($this->node instanceof Node);
assert($this->actionRequest instanceof ActionRequest);
/** @var string $renderingModeName */
$renderingModeName = $this->getOption('renderingModeName');

$runtimeVariables = new ComponentViewRuntimeVariables(
$siteNode,
$this->documentNode,
$subgraph,
$this->controllerContext->getRequest(),
$this->actionRequest,
$this->renderingModeService->findByName($renderingModeName)
);
if ($this->renderingEntryPoint) {
$factory = (new $this->renderingEntryPoint->className());
if ($this->renderingEntryPoint->isContentRendererDelegation()) {
/** @var ContentRenderer $factory */
$nodeType = $this->contentRepositoryRegistry->get($this->node->subgraphIdentity->contentRepositoryId)
$nodeType = $this->contentRepositoryRegistry->get($this->node->contentRepositoryId)
->getNodeTypeManager()->getNodeType($this->node->nodeTypeName);
if ($nodeType->isOfType(NodeTypeNameFactory::NAME_CONTENT_COLLECTION)) {
if ($nodeType?->isOfType(NodeTypeNameFactory::NAME_CONTENT_COLLECTION)) {
$component = $factory->forContentCollection($this->node, $runtimeVariables);
} else {
$cacheTags = new CacheTagSet();
Expand All @@ -128,31 +136,31 @@ public function render(): string
$component = $pageFactoryRelay->delegate($runtimeVariables);
}

return $component->render();
return $this->createStream($component->render());
}

private function findClosestDocument(ContentSubgraphInterface $subgraph, Node $node): ?Node
{
$nodeType = $this->contentRepositoryRegistry->get($subgraph->getIdentity()->contentRepositoryId)
$nodeType = $this->contentRepositoryRegistry->get($subgraph->getContentRepositoryId())
->getNodeTypeManager()->getNodeType($node->nodeTypeName);
if ($nodeType->isOfType(NodeTypeNameFactory::NAME_DOCUMENT)) {
if ($nodeType?->isOfType(NodeTypeNameFactory::NAME_DOCUMENT)) {
return $node;
}
return $subgraph->findClosestNode(
$node->nodeAggregateId,
$node->aggregateId,
FindClosestNodeFilter::create(nodeTypes: NodeTypeNameFactory::NAME_DOCUMENT)
);
}

private function findClosestSite(ContentSubgraphInterface $subgraph, Node $node): ?Node
{
$nodeType = $this->contentRepositoryRegistry->get($subgraph->getIdentity()->contentRepositoryId)
$nodeType = $this->contentRepositoryRegistry->get($subgraph->getContentRepositoryId())
->getNodeTypeManager()->getNodeType($node->nodeTypeName);
if ($nodeType->isOfType(NodeTypeNameFactory::NAME_SITE)) {
if ($nodeType?->isOfType(NodeTypeNameFactory::NAME_SITE)) {
return $node;
}
return $subgraph->findClosestNode(
$node->nodeAggregateId,
$node->aggregateId,
FindClosestNodeFilter::create(nodeTypes: NodeTypeNameFactory::NAME_SITE)
);
}
Expand Down
12 changes: 6 additions & 6 deletions Classes/Application/ContentRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ private function resolveCacheSegmentForContentCollection(
ComponentViewRuntimeVariables $runtimeVariables,
?string $additionalClasses = null,
): CacheSegment {
$cacheEntryIdentifier = 'node_' . $node->nodeAggregateId->value
. '_' . $runtimeVariables->documentNode->subgraphIdentity->contentStreamId->value
. '_' . $runtimeVariables->documentNode->subgraphIdentity->dimensionSpacePoint->hash
$cacheEntryIdentifier = 'node_' . $node->aggregateId->value
. '_' . $runtimeVariables->subgraph->getWorkspaceName()->value
. '_' . $runtimeVariables->subgraph->getDimensionSpacePoint()->hash
. '_' . $runtimeVariables->renderingMode->name . ($collectionName ? '_' . $collectionName->value : '');

$component = $this->componentCache->findComponent(
Expand All @@ -75,7 +75,7 @@ private function resolveCacheSegmentForContentCollection(
$contentCollection = $collectionName
? $runtimeVariables->subgraph->findNodeByPath(
$collectionName,
$node->nodeAggregateId,
$node->aggregateId,
) : $node;
assert($contentCollection instanceof Node);
$cacheTags = new CacheTagSet(
Expand All @@ -92,7 +92,7 @@ function (Node $childNode) use ($runtimeVariables, &$cacheTags): ComponentInterf
);
},
iterator_to_array($runtimeVariables->subgraph->findChildNodes(
$contentCollection->nodeAggregateId,
$contentCollection->aggregateId,
FindChildNodesFilter::create()
))
));
Expand All @@ -115,7 +115,7 @@ function (Node $childNode) use ($runtimeVariables, &$cacheTags): ComponentInterf
return new CacheSegment(
new CacheDirective(
$cacheEntryIdentifier,
$node->nodeAggregateId,
$node->aggregateId,
$collectionName,
null
),
Expand Down
13 changes: 8 additions & 5 deletions Classes/Application/NeosStuffFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@ public function getHeadStuff(ComponentViewRuntimeVariables $runtimeVariables): ?
'metaData' => [
'documentNode' => $this->nodeInfoHelper->serializedNodeAddress($runtimeVariables->documentNode),
'siteNode' => $this->nodeInfoHelper->serializedNodeAddress($runtimeVariables->siteNode),
'previewUrl' => $this->nodeInfoHelper->createRedirectToNode($runtimeVariables->documentNode, $this->uriService->getControllerContext()),
'previewUrl' => $this->nodeInfoHelper->createRedirectToNode(
$runtimeVariables->documentNode,
$this->uriService->getControllerContext()->getRequest()
),
'contentDimensions' => [
'active' => $this->contentDimensionsHelper->dimensionSpacePointArray(
$runtimeVariables->documentNode->subgraphIdentity->dimensionSpacePoint
$runtimeVariables->subgraph->getDimensionSpacePoint()
),
'allowedPresets' => $this->contentDimensionsHelper->allowedPresetsByName(
$runtimeVariables->documentNode->subgraphIdentity->dimensionSpacePoint,
$runtimeVariables->documentNode->subgraphIdentity->contentRepositoryId
$runtimeVariables->subgraph->getDimensionSpacePoint(),
$runtimeVariables->subgraph->getContentRepositoryId()
) ?: new \stdClass()
],
'documentNodeSerialization' => $this->nodeInfoHelper->renderNodeWithPropertiesAndChildrenInformation(
$runtimeVariables->documentNode,
$this->uriService->getControllerContext()
$this->uriService->getControllerContext()->getRequest()
)
]
];
Expand Down
14 changes: 8 additions & 6 deletions Classes/Domain/NodeMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function getAugmenterAttributesForContentNode(
?RenderingEntryPoint $renderingEntryPoint = null,
?string $additionalClasses = null
): ?array {
$contentRepository = $this->contentRepositoryRegistry->get($contentNode->subgraphIdentity->contentRepositoryId);
$contentRepository = $this->contentRepositoryRegistry->get($contentNode->contentRepositoryId);
$renderingEntryPoint ??= RenderingEntryPoint::forContentRendererDelegation();

$nodeAddress = NodeAddressFactory::create($contentRepository)->createFromNode($contentNode);
Expand All @@ -37,7 +37,7 @@ public function getAugmenterAttributesForContentNode(
$attributes['data-__neos-node-contextpath'] = $nodeAddress->serializeForUri();
if (
$contentRepository->getNodeTypeManager()->getNodeType($contentNode->nodeTypeName)
->isOfType(NodeTypeNameFactory::NAME_CONTENT_COLLECTION)
?->isOfType(NodeTypeNameFactory::NAME_CONTENT_COLLECTION)
) {
$attributes['class'] = 'neos-contentcollection ' . $additionalClasses;
} elseif ($additionalClasses) {
Expand All @@ -49,9 +49,11 @@ public function getAugmenterAttributesForContentNode(

public function getScriptForContentNode(Node $contentNode): string
{
$contentRepository = $this->contentRepositoryRegistry->get($contentNode->subgraphIdentity->contentRepositoryId);
$contentRepository = $this->contentRepositoryRegistry->get($contentNode->contentRepositoryId);
$nodeAddress = NodeAddressFactory::create($contentRepository)->createFromNode($contentNode);
$serializedNode = json_encode($this->nodeInfoHelper->renderNode($contentNode));

// TODO illegal dependency on ui
$serializedNode = json_encode($this->nodeInfoHelper->renderNodeWithPropertiesAndChildrenInformation($contentNode));

return "<script data-neos-nodedata>(function(){(this['@Neos.Neos.Ui:Nodes'] = this['@Neos.Neos.Ui:Nodes'] || {})['{$nodeAddress->serializeForUri()}'] = {$serializedNode}})()</script>";
}
Expand All @@ -61,8 +63,8 @@ public function getScriptForContentNode(Node $contentNode): string
*/
public function forDocumentNode(Node $documentNode, ?string $locator = null, ?Node $siteNode = null): ?array
{
$contentRepository = $this->contentRepositoryRegistry->get($documentNode->subgraphIdentity->contentRepositoryId);
$locator = is_string($locator) ? $locator : '/<Neos.Neos:Document>/' . $documentNode->nodeAggregateId->value;
$contentRepository = $this->contentRepositoryRegistry->get($documentNode->contentRepositoryId);
$locator = is_string($locator) ? $locator : '/<Neos.Neos:Document>/' . $documentNode->aggregateId->value;

$nodeAddress = NodeAddressFactory::create($contentRepository)->createFromNode($documentNode);
$metadata['data-__neos-node-contextpath'] = $nodeAddress->serializeForUri();
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/UriService.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function setControllerContext(ControllerContext $controllerContext): void
public function getNodeUri(Node $documentNode, bool $absolute = false, ?string $format = null): UriInterface
{
$contentRepository = $this->contentRepositoryRegistry->get(
$documentNode->subgraphIdentity->contentRepositoryId
$documentNode->contentRepositoryId
);
$nodeAddressFactory = NodeAddressFactory::create($contentRepository);
$nodeAddress = $nodeAddressFactory->createFromNode($documentNode);
Expand Down
Loading

0 comments on commit 96468a0

Please sign in to comment.