Skip to content

Commit

Permalink
Merge pull request #5020 from mhsdesign/task/5019-make-node-label-pur…
Browse files Browse the repository at this point in the history
…e-neos-concept

!!! TASK: Make node label pure neos concept
  • Loading branch information
kitsunet committed May 14, 2024
2 parents 96ce9e9 + c9ed7be commit 5d14a98
Show file tree
Hide file tree
Showing 35 changed files with 207 additions and 354 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
namespace Neos\ContentRepository\BehavioralTests\TestSuite\Behavior;

use Behat\Gherkin\Node\PyStringNode;
use Neos\ContentRepository\Core\NodeType\NodeLabelGeneratorFactoryInterface;
use Neos\ContentRepository\Core\NodeType\NodeLabelGeneratorInterface;
use Neos\ContentRepository\Core\NodeType\NodeType;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepositoryRegistry\Factory\NodeTypeManager\NodeTypeManagerFactoryInterface;
use Symfony\Component\Yaml\Yaml;
Expand All @@ -45,18 +41,7 @@ public function build(ContentRepositoryId $contentRepositoryId, array $options):
public static function initializeWithPyStringNode(PyStringNode $nodeTypesToUse): void
{
self::$nodeTypesToUse = new NodeTypeManager(
fn (): array => Yaml::parse($nodeTypesToUse->getRaw()) ?? [],
new class implements NodeLabelGeneratorFactoryInterface {
public function create(NodeType $nodeType): NodeLabelGeneratorInterface
{
return new class implements NodeLabelGeneratorInterface {
public function getLabel(Node $node): string
{
return $node->nodeTypeName->value;
}
};
}
}
fn (): array => Yaml::parse($nodeTypesToUse->getRaw()) ?? []
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Command\CreateRootWorkspace;
use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Command\CreateWorkspace;
use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Command\RebaseWorkspace;
use Neos\ContentRepository\Core\NodeType\DefaultNodeLabelGeneratorFactory;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
Expand Down Expand Up @@ -90,8 +89,7 @@ public function getContentDimensionsOrderedByPriority(): array
]
]
]
],
new DefaultNodeLabelGeneratorFactory()
]
);
$this->contentRepositoryRegistry = $this->objectManager->get(ContentRepositoryRegistry::class);

Expand Down

This file was deleted.

This file was deleted.

19 changes: 1 addition & 18 deletions Neos.ContentRepository.Core/Classes/NodeType/NodeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ final class NodeType
*/
protected array $declaredSuperTypes;

protected ?NodeLabelGeneratorInterface $nodeLabelGenerator = null;

/**
* Whether or not this node type has been initialized (e.g. if it has been postprocessed)
*/
Expand All @@ -87,8 +85,7 @@ final class NodeType
public function __construct(
NodeTypeName $name,
array $declaredSuperTypes,
array $configuration,
private readonly NodeLabelGeneratorFactoryInterface $nodeLabelGeneratorFactory
array $configuration
) {
$this->name = $name;
$this->declaredSuperTypes = $declaredSuperTypes;
Expand Down Expand Up @@ -396,20 +393,6 @@ public function getOptions(): array
return ($this->fullConfiguration['options'] ?? []);
}

/**
* Return the node label generator class for the given node
*/
public function getNodeLabelGenerator(): NodeLabelGeneratorInterface
{
$this->initialize();

if ($this->nodeLabelGenerator === null) {
$this->nodeLabelGenerator = $this->nodeLabelGeneratorFactory->create($this);
}

return $this->nodeLabelGenerator;
}

/**
* Return the array with the defined properties. The key is the property name,
* the value the property configuration. There are no guarantees on how the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ final class NodeTypeManager
* @internal
*/
public function __construct(
private readonly \Closure $nodeTypeConfigLoader,
private readonly NodeLabelGeneratorFactoryInterface $nodeLabelGeneratorFactory
private readonly \Closure $nodeTypeConfigLoader
) {
}

Expand Down Expand Up @@ -319,8 +318,7 @@ private function loadNodeType(string $nodeTypeName, array &$completeNodeTypeConf
$nodeType = new NodeType(
NodeTypeName::fromString($nodeTypeName),
$superTypes,
$nodeTypeConfiguration,
$this->nodeLabelGeneratorFactory
$nodeTypeConfiguration
);

$this->cachedNodeTypes[$nodeTypeName] = $nodeType;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,25 @@ public function hasProperty(string $propertyName): bool
}

/**
* Returns the node label as generated by the configured node label generator
* Returned the node label as generated by the configured node label generator.
*
* @return string
* In PHP please use Neos' {@see NodeLabelGeneratorInterface} instead.
*
* For Fusion please use the FlowQuery operation:
* ```
* ${q(node).label()}
* ```
*
* @deprecated will be removed before the final 9.0 release
*/
public function getLabel(): string
{
return $this->nodeType?->getNodeLabelGenerator()->getLabel($this) ?: $this->nodeTypeName->value;
if (!class_exists(\Neos\Neos\Domain\NodeLabel\DelegatingNodeLabelRenderer::class)) {
throw new \BadMethodCallException('node labels are removed from standalone cr.');
}
// highly illegal
/** @phpstan-ignore-next-line */
return (new \Neos\Neos\Domain\NodeLabel\DelegatingNodeLabelRenderer())->getLabel($this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace Neos\ContentRepository\Core\Tests\Unit\Feature\NodeCreation\Dto;

use Neos\ContentRepository\Core\Feature\NodeCreation\Dto\NodeAggregateIdsByNodePaths;
use Neos\ContentRepository\Core\NodeType\DefaultNodeLabelGeneratorFactory;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodePath;
Expand Down Expand Up @@ -56,8 +55,7 @@ public function testCompleteForNodeOfType(NodeAggregateIdsByNodePaths $subject,
]
]
]
],
new DefaultNodeLabelGeneratorFactory()
]
);

$completeSubject = $subject->completeForNodeOfType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* source code.
*/

use Neos\ContentRepository\Core\NodeType\DefaultNodeLabelGeneratorFactory;
use Neos\ContentRepository\Core\NodeType\NodeType;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
Expand Down Expand Up @@ -43,8 +42,7 @@ public function setUp(): void
protected function prepareNodeTypeManager(array $nodeTypesFixtureData)
{
$this->nodeTypeManager = new NodeTypeManager(
fn() => $nodeTypesFixtureData,
new DefaultNodeLabelGeneratorFactory()
fn() => $nodeTypesFixtureData
);
}

Expand Down Expand Up @@ -447,8 +445,7 @@ public function getAutoCreatedChildNodesReturnsLowercaseNames()
public function rootNodeTypeIsAlwaysPresent()
{
$nodeTypeManager = new NodeTypeManager(
fn() => [],
new DefaultNodeLabelGeneratorFactory()
fn() => []
);
self::assertTrue($nodeTypeManager->hasNodeType(NodeTypeName::ROOT_NODE_TYPE_NAME));
self::assertInstanceOf(NodeType::class, $nodeTypeManager->getNodeType(NodeTypeName::ROOT_NODE_TYPE_NAME));
Expand All @@ -460,8 +457,7 @@ public function rootNodeTypeIsAlwaysPresent()
public function rootNodeTypeIsPresentAfterOverride()
{
$nodeTypeManager = new NodeTypeManager(
fn() => [],
new DefaultNodeLabelGeneratorFactory()
fn() => []
);
$nodeTypeManager->overrideNodeTypes(['Some:NewNodeType' => []]);
self::assertTrue($nodeTypeManager->hasNodeType(NodeTypeName::fromString('Some:NewNodeType')));
Expand Down

0 comments on commit 5d14a98

Please sign in to comment.