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

BUGFIX: Reduce nodetype schema size #4561

Merged
merged 4 commits into from
Oct 25, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 45 additions & 19 deletions Neos.Neos/Classes/Service/NodeTypeSchemaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/

use Neos\Flow\Annotations as Flow;
use Neos\ContentRepository\Domain\Model\NodeType;

/**
* Renders the Node Type Schema in a format the User Interface understands; additionally pre-calculating node constraints
Expand All @@ -27,6 +26,16 @@ class NodeTypeSchemaBuilder
*/
protected $nodeTypeManager;

/**
* The Neos UI package needs a few additional abstract nodetypes to be present in the schema.
* This will be properly cleaned up when this service is moved into the Neos.UI package as we only
* need the schema there.
*
* @Flow\InjectConfiguration(path="nodeTypeRoles", package="Neos.Neos.Ui")
* @var array
*/
protected $nodeTypeRoles;

/**
* The preprocessed node type schema contains everything we need for the UI:
*
Expand Down Expand Up @@ -54,19 +63,34 @@ public function generateNodeTypeSchema()
'constraints' => $this->generateConstraints()
];

$nodeTypes = $this->nodeTypeManager->getNodeTypes(true);
/** @var NodeType $nodeType */
// We need skip abstract nodetypes as they are not instantiated by the UI
$nodeTypes = $this->nodeTypeManager->getNodeTypes(false);

// Get special abstract nodetypes required by the Neos.UI
if ($this->nodeTypeRoles) {
$additionalNodeTypeNames = array_values($this->nodeTypeRoles);
foreach ($additionalNodeTypeNames as $additionalNodeTypeName) {
$nodeTypes[$additionalNodeTypeName] = $this->nodeTypeManager->getNodeType($additionalNodeTypeName);
}
}

foreach ($nodeTypes as $nodeTypeName => $nodeType) {
// Skip abstract nodetypes which might have been added by the Neos.UI `nodeTypeRoles` configuration
if ($nodeType->isAbstract() === false) {
$configuration = $nodeType->getFullConfiguration();
$schema['nodeTypes'][$nodeTypeName] = $configuration;
$schema['nodeTypes'][$nodeTypeName]['label'] = $nodeType->getLabel();
}

$schema['inheritanceMap']['subTypes'][$nodeTypeName] = [];
foreach ($this->nodeTypeManager->getSubNodeTypes($nodeType->getName(), true) as $subNodeType) {
/** @var NodeType $subNodeType */
$schema['inheritanceMap']['subTypes'][$nodeTypeName][] = $subNodeType->getName();
// Remove the postprocessors, as they are not needed in the UI
unset($schema['nodeTypes'][$nodeTypeName]['postprocessors']);

$subTypes = [];
foreach ($this->nodeTypeManager->getSubNodeTypes($nodeType->getName(), false) as $subNodeType) {
$subTypes[] = $subNodeType->getName();
}
if ($subTypes) {
$schema['inheritanceMap']['subTypes'][$nodeTypeName] = $subTypes;
}
}

Expand All @@ -81,29 +105,31 @@ public function generateNodeTypeSchema()
protected function generateConstraints()
{
$constraints = [];
$nodeTypes = $this->nodeTypeManager->getNodeTypes(true);
/** @var NodeType $nodeType */
$nodeTypes = $this->nodeTypeManager->getNodeTypes(false);
foreach ($nodeTypes as $nodeTypeName => $nodeType) {
if ($nodeType->isAbstract()) {
continue;
}
$constraints[$nodeTypeName] = [
'nodeTypes' => [],
'childNodes' => []
];
$nodeTypeConstraints = [];
$childNodeConstraints = [];

foreach ($nodeTypes as $innerNodeTypeName => $innerNodeType) {
if ($nodeType->allowsChildNodeType($innerNodeType)) {
$constraints[$nodeTypeName]['nodeTypes'][$innerNodeTypeName] = true;
$nodeTypeConstraints[$innerNodeTypeName] = true;
}
}

foreach ($nodeType->getAutoCreatedChildNodes() as $key => $_x) {
foreach (array_keys($nodeType->getAutoCreatedChildNodes()) as $key) {
foreach ($nodeTypes as $innerNodeTypeName => $innerNodeType) {
if ($nodeType->allowsGrandchildNodeType($key, $innerNodeType)) {
$constraints[$nodeTypeName]['childNodes'][$key]['nodeTypes'][$innerNodeTypeName] = true;
$childNodeConstraints[$key]['nodeTypes'][$innerNodeTypeName] = true;
}
}
}

if ($nodeTypeConstraints || $childNodeConstraints) {
$constraints[$nodeTypeName] = [
'nodeTypes' => $nodeTypeConstraints,
'childNodes' => $childNodeConstraints,
];
}
}

return $constraints;
Expand Down
10 changes: 5 additions & 5 deletions Neos.Neos/Tests/Functional/Service/NodeTypeSchemaBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public function theNodeTypeSchemaIncludesSubTypesInheritanceMap()
{
$subTypesDefinition = $this->schema['inheritanceMap']['subTypes'];

self::assertContains('Neos.Neos.BackendSchemaControllerTest:Document', $subTypesDefinition['Neos.Neos.BackendSchemaControllerTest:Node']);
self::assertContains('Neos.Neos.BackendSchemaControllerTest:Content', $subTypesDefinition['Neos.Neos.BackendSchemaControllerTest:Node']);
self::assertContains('Neos.Neos.BackendSchemaControllerTest:Page', $subTypesDefinition['Neos.Neos.BackendSchemaControllerTest:Node']);
self::assertContains('Neos.Neos.BackendSchemaControllerTest:SubPage', $subTypesDefinition['Neos.Neos.BackendSchemaControllerTest:Node']);
self::assertContains('Neos.Neos.BackendSchemaControllerTest:Text', $subTypesDefinition['Neos.Neos.BackendSchemaControllerTest:Node']);
self::assertContains('Neos.Neos.BackendSchemaControllerTest:Page', $subTypesDefinition['Neos.Neos.BackendSchemaControllerTest:Document']);
self::assertContains('Neos.Neos.BackendSchemaControllerTest:Folder', $subTypesDefinition['Neos.Neos.BackendSchemaControllerTest:Document']);
self::assertContains('Neos.Neos.BackendSchemaControllerTest:SubPage', $subTypesDefinition['Neos.Neos.BackendSchemaControllerTest:Page']);
self::assertContains('Neos.Neos.BackendSchemaControllerTest:Text', $subTypesDefinition['Neos.Neos.BackendSchemaControllerTest:Content']);
self::assertContains('Neos.Neos.BackendSchemaControllerTest:TwoColumn', $subTypesDefinition['Neos.Neos.BackendSchemaControllerTest:Content']);
}

/**
Expand Down