forked from neos/neos-development-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Introduce Neos 9 backport of Node access FlowQuery operations
see neos#5022
- Loading branch information
Showing
4 changed files
with
291 additions
and
0 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
Neos.ContentRepository.NodeAccess/Classes/FlowQueryOperations/IdOperation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
namespace Neos\ContentRepository\Eel\FlowQueryOperations; | ||
|
||
/* | ||
* This file is part of the Neos.ContentRepository package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\ContentRepository\Core\Projection\ContentGraph\Node; | ||
use Neos\Eel\FlowQuery\FlowQuery; | ||
use Neos\Eel\FlowQuery\FlowQueryException; | ||
use Neos\Eel\FlowQuery\Operations\AbstractOperation; | ||
|
||
/** | ||
* Used to access the Node's identifier of a ContentRepository Node. | ||
*/ | ||
class IdOperation extends AbstractOperation | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @var string | ||
*/ | ||
protected static $shortName = 'id'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @var integer | ||
*/ | ||
protected static $priority = 100; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @var boolean | ||
*/ | ||
protected static $final = true; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* We can only handle ContentRepository Nodes. | ||
* | ||
* @param array<int, mixed> $context $context onto which this operation should be applied (array or array-like object) | ||
* @return boolean | ||
*/ | ||
public function canEvaluate($context): bool | ||
{ | ||
return (isset($context[0]) && $context[0] instanceof Node); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param FlowQuery<int,mixed> $flowQuery the FlowQuery object | ||
* @param array<int,mixed> $arguments the arguments for this operation | ||
* @return mixed | ||
* @throws FlowQueryException | ||
*/ | ||
public function evaluate(FlowQuery $flowQuery, array $arguments) | ||
{ | ||
if ($arguments !== []) { | ||
throw new FlowQueryException(static::$shortName . '() does not require any argument.', 1715510778); | ||
} | ||
$node = $flowQuery->getContext()[0] ?? null; | ||
if (!$node instanceof Node) { | ||
return null; | ||
} | ||
return $node->nodeAggregateId->value; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
Neos.ContentRepository.NodeAccess/Classes/FlowQueryOperations/LabelOperation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
namespace Neos\ContentRepository\Eel\FlowQueryOperations; | ||
|
||
/* | ||
* This file is part of the Neos.ContentRepository package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\ContentRepository\Core\Projection\ContentGraph\Node; | ||
use Neos\Eel\FlowQuery\FlowQuery; | ||
use Neos\Eel\FlowQuery\FlowQueryException; | ||
use Neos\Eel\FlowQuery\Operations\AbstractOperation; | ||
|
||
/** | ||
* Used to access the Node's label of a ContentRepository Node. | ||
*/ | ||
class LabelOperation extends AbstractOperation | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @var string | ||
*/ | ||
protected static $shortName = 'label'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @var integer | ||
*/ | ||
protected static $priority = 100; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @var boolean | ||
*/ | ||
protected static $final = true; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* We can only handle ContentRepository Nodes. | ||
* | ||
* @param array<int, mixed> $context $context onto which this operation should be applied (array or array-like object) | ||
* @return boolean | ||
*/ | ||
public function canEvaluate($context): bool | ||
{ | ||
return (isset($context[0]) && $context[0] instanceof Node); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param FlowQuery<int,mixed> $flowQuery the FlowQuery object | ||
* @param array<int,mixed> $arguments the arguments for this operation | ||
* @return mixed | ||
* @throws FlowQueryException | ||
*/ | ||
public function evaluate(FlowQuery $flowQuery, array $arguments) | ||
{ | ||
if ($arguments !== []) { | ||
throw new FlowQueryException(static::$shortName . '() does not require any argument.', 1715510778); | ||
} | ||
$node = $flowQuery->getContext()[0] ?? null; | ||
if (!$node instanceof Node) { | ||
return null; | ||
} | ||
return $node->getLabel(); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
Neos.ContentRepository.NodeAccess/Classes/FlowQueryOperations/NodeTypeNameOperation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
namespace Neos\ContentRepository\Eel\FlowQueryOperations; | ||
|
||
/* | ||
* This file is part of the Neos.ContentRepository package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\ContentRepository\Core\Projection\ContentGraph\Node; | ||
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; | ||
use Neos\Eel\FlowQuery\FlowQuery; | ||
use Neos\Eel\FlowQuery\FlowQueryException; | ||
use Neos\Eel\FlowQuery\Operations\AbstractOperation; | ||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Neos\Domain\Service\NodeTypeNameFactory; | ||
|
||
/** | ||
* Used to access the NodeTypeName of a ContentRepository Node. | ||
*/ | ||
class NodeTypeNameOperation extends AbstractOperation | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @var string | ||
*/ | ||
protected static $shortName = 'nodeTypeName'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @var integer | ||
*/ | ||
protected static $priority = 100; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @var boolean | ||
*/ | ||
protected static $final = true; | ||
|
||
/** | ||
* @Flow\Inject | ||
*/ | ||
protected ContentRepositoryRegistry $contentRepositoryRegistry; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* We can only handle ContentRepository Nodes. | ||
* | ||
* @param array<int, mixed> $context $context onto which this operation should be applied (array or array-like object) | ||
* @return boolean | ||
*/ | ||
public function canEvaluate($context): bool | ||
{ | ||
return (isset($context[0]) && $context[0] instanceof Node); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param FlowQuery<int,mixed> $flowQuery the FlowQuery object | ||
* @param array<int,mixed> $arguments the arguments for this operation | ||
* @return mixed | ||
* @throws FlowQueryException | ||
*/ | ||
public function evaluate(FlowQuery $flowQuery, array $arguments) | ||
{ | ||
if ($arguments !== []) { | ||
throw new FlowQueryException(static::$shortName . '() does not require any argument.', 1715510778); | ||
} | ||
$node = $flowQuery->getContext()[0] ?? null; | ||
if (!$node instanceof Node) { | ||
return null; | ||
} | ||
|
||
$contentRepository = $this->contentRepositoryRegistry->get($node->subgraphIdentity->contentRepositoryId); | ||
|
||
return $contentRepository->getNodeTypeManager()->hasNodeType($node->nodeTypeName) | ||
? $node->nodeType->name | ||
: NodeTypeNameFactory::forFallback()->value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters