Skip to content

Commit

Permalink
Merge pull request #187 from neos/task/adjustToRemovedNodeContentSubg…
Browse files Browse the repository at this point in the history
…raphIdenityAndNodeType

TASK: Adjust to Removal of Node::subgraphIdentity
  • Loading branch information
mhsdesign authored Jun 20, 2024
2 parents bc6b3a3 + 32c8d5c commit 2e5ec42
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions Classes/Fusion/XmlSitemapUrlsImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

use Neos\ContentRepository\Core\NodeType\NodeType;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\NodeType\NodeTypeNames;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindSubtreeFilter;
Expand All @@ -24,13 +25,10 @@
use Neos\Flow\Persistence\Doctrine\PersistenceManager;
use Neos\Fusion\FusionObjects\AbstractFusionObject;
use Neos\Media\Domain\Model\ImageInterface;
use Neos\Neos\Utility\NodeTypeWithFallbackProvider;
use Neos\Utility\Exception\PropertyNotAccessibleException;

class XmlSitemapUrlsImplementation extends AbstractFusionObject
{
use NodeTypeWithFallbackProvider;

#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

Expand Down Expand Up @@ -97,14 +95,14 @@ public function evaluate(): array
$startingPoint = $this->getStartingPoint();
$subgraph = $this->contentRepositoryRegistry->subgraphForNode($startingPoint);

$nodeTypeManager = $this->contentRepositoryRegistry->get($startingPoint->subgraphIdentity->contentRepositoryId)->getNodeTypeManager();
$nodeTypeManager = $this->contentRepositoryRegistry->get($startingPoint->contentRepositoryId)->getNodeTypeManager();
$nodeTypeNames = NodeTypeNames::fromArray(array_map(
fn(NodeType $nodeType): NodeTypeName => $nodeType->name,
$nodeTypeManager->getSubNodeTypes('Neos.Neos:Document', false)
));

$subtree = $subgraph->findSubtree(
$startingPoint->nodeAggregateId,
$startingPoint->aggregateId,
FindSubtreeFilter::create(nodeTypes: NodeTypeCriteria::create($nodeTypeNames, NodeTypeNames::createEmpty()))
);

Expand Down Expand Up @@ -143,8 +141,9 @@ private function getAssetPropertiesForNodeType(NodeType $nodeType): array
protected function collectItems(array &$items, Subtree $subtree): void
{
$node = $subtree->node;
$nodeTypeManager = $this->contentRepositoryRegistry->get($node->contentRepositoryId)->getNodeTypeManager();

if ($this->isDocumentNodeToBeIndexed($node)) {
if ($this->isDocumentNodeToBeIndexed($node, $nodeTypeManager)) {
$item = [
'node' => $node,
'lastModificationDateTime' => $node->timestamps->lastModified ?: $node->timestamps->created,
Expand All @@ -156,7 +155,6 @@ protected function collectItems(array &$items, Subtree $subtree): void
}

if ($this->getIncludeImageUrls()) {
$nodeTypeManager = $this->contentRepositoryRegistry->get($node->subgraphIdentity->contentRepositoryId)->getNodeTypeManager();
$collectionNodeTypeNames = array_map(
fn(NodeType $nodeType): NodeTypeName => $nodeType->name,
$nodeTypeManager->getSubNodeTypes('Neos.Neos:ContentCollection', false)
Expand All @@ -170,11 +168,11 @@ protected function collectItems(array &$items, Subtree $subtree): void

$subgraph = $this->contentRepositoryRegistry->subgraphForNode($node);
$contentSubtree = $subgraph->findSubtree(
$node->nodeAggregateId,
$node->aggregateId,
FindSubtreeFilter::create(nodeTypes: NodeTypeCriteria::create($nodeTypeNames, NodeTypeNames::createEmpty()))
);

$this->resolveImages($contentSubtree, $item);
$this->resolveImages($contentSubtree, $item, $nodeTypeManager);
}

$items[] = $item;
Expand All @@ -191,10 +189,11 @@ protected function collectItems(array &$items, Subtree $subtree): void
* @return void
* @throws PropertyNotAccessibleException
*/
protected function resolveImages(Subtree $subtree, array &$item): void
protected function resolveImages(Subtree $subtree, array &$item, NodeTypeManager $nodeTypeManager): void
{
$node = $subtree->node;
$assetPropertiesForNodeType = $this->getAssetPropertiesForNodeType($this->getNodeType($node));
$nodeType = $nodeTypeManager->getNodeType($node->nodeTypeName);
$assetPropertiesForNodeType = $nodeType ? $this->getAssetPropertiesForNodeType($nodeType) : [];

foreach ($assetPropertiesForNodeType as $propertyName) {
if (is_array($node->getProperty($propertyName)) && !empty($node->getProperty($propertyName))) {
Expand All @@ -209,22 +208,23 @@ protected function resolveImages(Subtree $subtree, array &$item): void
}

foreach ($subtree->children as $childSubtree) {
$this->resolveImages($childSubtree, $item);
$this->resolveImages($childSubtree, $item, $nodeTypeManager);
}
}

/**
* Return TRUE/FALSE if the node is currently hidden; taking the "renderHiddenInMenu" configuration
* of the Menu Fusion object into account.
*/
protected function isDocumentNodeToBeIndexed(Node $node): bool
protected function isDocumentNodeToBeIndexed(Node $node, NodeTypeManager $nodeTypeManager): bool
{
return !$this->getNodeType($node)->isOfType('Neos.Seo:NoindexMixin')
$nodeType = $nodeTypeManager->getNodeType($node->nodeTypeName);
return !$nodeType?->isOfType('Neos.Seo:NoindexMixin')
&& ($this->getRenderHiddenInMenu() || $node->getProperty('hiddenInMenu') !== true)
&& $node->getProperty('metaRobotsNoindex') !== true
&& (
(string)$node->getProperty('canonicalLink') === ''
|| substr($node->getProperty('canonicalLink'), 7) === $node->nodeAggregateId->value
|| substr($node->getProperty('canonicalLink'), 7) === $node->aggregateId->value
);
}
}

0 comments on commit 2e5ec42

Please sign in to comment.