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

FEATURE: Separate properties and references in Neos UI #5156

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ protected function addLabelsToNodeTypeConfiguration(string $nodeTypeName, array
}

if (isset($configuration['properties'])) {
$this->setPropertyLabels($nodeTypeName, $configuration, $superTypeConfigResolver);
$this->setLabels($nodeTypeName, $configuration['properties'], $superTypeConfigResolver, 'properties');
}
if (isset($configuration['references'])) {
$this->setLabels($nodeTypeName, $configuration['references'], $superTypeConfigResolver, 'references');
}
}

Expand All @@ -73,18 +76,19 @@ protected function addLabelsToNodeTypeConfiguration(string $nodeTypeName, array
* @param SuperTypeConfigResolver $superTypeConfigResolver
* @return void
*/
protected function setPropertyLabels(string $nodeTypeName, array &$configuration, SuperTypeConfigResolver $superTypeConfigResolver)
protected function setLabels(string $nodeTypeName, array &$configuration, SuperTypeConfigResolver $superTypeConfigResolver, string $configurationType)
{
$nodeTypeLabelIdPrefix = $this->generateNodeTypeLabelIdPrefix($nodeTypeName);
foreach ($configuration['properties'] as $propertyName => &$propertyConfiguration) {
foreach ($configuration as $propertyName => &$propertyConfiguration) {
if (!isset($propertyConfiguration['ui'])) {
continue;
}

if ($this->shouldFetchTranslation($propertyConfiguration['ui'])) {
$propertyConfiguration['ui']['label'] = $this->getPropertyLabelTranslationId(
$propertyConfiguration['ui']['label'] = $this->getLabelTranslationId(
$nodeTypeLabelIdPrefix,
$propertyName
$propertyName,
$configurationType
);
}

Expand All @@ -100,8 +104,8 @@ protected function setPropertyLabels(string $nodeTypeName, array &$configuration
$hasEditorOptions = isset($propertyConfiguration['ui']['inspector']['editorOptions']);

if ($hasEditor && $hasEditorOptions) {
$translationIdGenerator = function ($path) use ($nodeTypeLabelIdPrefix, $propertyName) {
return $this->getPropertyConfigurationTranslationId($nodeTypeLabelIdPrefix, $propertyName, $path);
$translationIdGenerator = function ($path) use ($nodeTypeLabelIdPrefix, $propertyName, $configurationType) {
return $this->getConfigurationTranslationId($nodeTypeLabelIdPrefix, $propertyName, $path, $configurationType);
};
$this->applyEditorLabels(
$nodeTypeLabelIdPrefix,
Expand All @@ -120,26 +124,32 @@ protected function setPropertyLabels(string $nodeTypeName, array &$configuration
)
) {
$propertyConfiguration['ui']['inline']['editorOptions']['placeholder']
= $this->getPropertyConfigurationTranslationId(
= $this->getConfigurationTranslationId(
$nodeTypeLabelIdPrefix,
$propertyName,
'ui.inline.editorOptions.placeholder'
'ui.inline.editorOptions.placeholder',
$configurationType
);
}

if (
isset($propertyConfiguration['ui']['help']['message'])
&& $this->shouldFetchTranslation($propertyConfiguration['ui']['help'], 'message')
) {
$propertyConfiguration['ui']['help']['message'] = $this->getPropertyConfigurationTranslationId(
$propertyConfiguration['ui']['help']['message'] = $this->getConfigurationTranslationId(
$nodeTypeLabelIdPrefix,
$propertyName,
'ui.help.message'
'ui.help.message',
$configurationType
);
}
if (isset($propertyConfiguration['properties'])) {
$this->setLabels($nodeTypeName, $propertyConfiguration['properties'], $superTypeConfigResolver, $propertyName . '.properties');
}
}
}


/**
* Resolve help message thumbnail url
*
Expand Down Expand Up @@ -226,7 +236,7 @@ protected function applyEditorLabels(
* @param array<string,mixed> $configuration
* @return void
*/
protected function setGlobalUiElementLabels(string $nodeTypeName, array &$configuration)
protected function setGlobalUiElementLabels(string $nodeTypeName, array &$configuration): void
{
$nodeTypeLabelIdPrefix = $this->generateNodeTypeLabelIdPrefix($nodeTypeName);
if ($this->shouldFetchTranslation($configuration['ui'])) {
Expand Down Expand Up @@ -318,7 +328,7 @@ protected function setGlobalUiElementLabels(string $nodeTypeName, array &$config
* @param string $fieldName Name of the possibly existing subfield
* @return boolean
*/
protected function shouldFetchTranslation(array $parentConfiguration, $fieldName = 'label')
protected function shouldFetchTranslation(array $parentConfiguration, string $fieldName = 'label'): bool
{
$fieldValue = array_key_exists($fieldName, $parentConfiguration) ? $parentConfiguration[$fieldName] : '';

Expand All @@ -333,7 +343,7 @@ protected function shouldFetchTranslation(array $parentConfiguration, $fieldName
* @param string $elementName
* @return string
*/
protected function getInspectorElementTranslationId($nodeTypeSpecificPrefix, $elementType, $elementName)
protected function getInspectorElementTranslationId(string $nodeTypeSpecificPrefix, string $elementType, string $elementName): string
{
return $nodeTypeSpecificPrefix . $elementType . '.' . $elementName;
}
Expand All @@ -345,9 +355,9 @@ protected function getInspectorElementTranslationId($nodeTypeSpecificPrefix, $el
* @param string $propertyName
* @return string
*/
protected function getPropertyLabelTranslationId($nodeTypeSpecificPrefix, $propertyName)
protected function getLabelTranslationId(string $nodeTypeSpecificPrefix, string $propertyName, string $configurationType): string
{
return $nodeTypeSpecificPrefix . 'properties.' . $propertyName;
return $nodeTypeSpecificPrefix . $configurationType . '.' . $propertyName;
}

/**
Expand All @@ -358,9 +368,9 @@ protected function getPropertyLabelTranslationId($nodeTypeSpecificPrefix, $prope
* @param string $labelPath
* @return string
*/
protected function getPropertyConfigurationTranslationId($nodeTypeSpecificPrefix, $propertyName, $labelPath)
protected function getConfigurationTranslationId(string $nodeTypeSpecificPrefix, string $propertyName, string $labelPath, string $configurationType): string
{
return $nodeTypeSpecificPrefix . 'properties.' . $propertyName . '.' . $labelPath;
return $nodeTypeSpecificPrefix . $configurationType . '.' . $propertyName . '.' . $labelPath;
pKallert marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
namespace Neos\ContentRepositoryRegistry\Tests\Unit\Configuration;

/*
* 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\ContentRepositoryRegistry\Configuration\NodeTypeEnrichmentService;
use Neos\Flow\Core\ApplicationContext;
use Neos\Flow\Package\FlowPackageInterface;
use Neos\Flow\Tests\UnitTestCase;
use Neos\Utility\Files;
use Symfony\Component\Yaml\Yaml;

class NodeTypeEnrichmentServiceTest extends UnitTestCase
{
private ?NodeTypeEnrichmentService $nodeTypeEnrichmentService;

public function setUp(): void
{
$this->nodeTypeEnrichmentService = new NodeTypeEnrichmentService();
}


/**
* @test
*/
public function EnrichNodeTypeLabelsConfig(): void
{
$nodeConfiguration = YAML::parse(<<<'YAML'
'Neos.Enrichment:Translation':
properties:
title:
type: string
ui:
label: i18n
references:
docReference:
type: reference
ui:
label: i18n
properties:
referenceProperty:
type: text
ui:
label: i18n
YAML);

$expectedResult = YAML::parse(<<<'YAML'
'Neos.Enrichment:Translation':
properties:
title:
type: string
ui:
label: Neos.Enrichment:NodeTypes.Translation:properties.title
references:
docReference:
type: reference
ui:
label: Neos.Enrichment:NodeTypes.Translation:references.docReference
properties:
referenceProperty:
type: text
ui:
label: Neos.Enrichment:NodeTypes.Translation:docReference.properties.referenceProperty
YAML);

$actualResult = $this->nodeTypeEnrichmentService->enrichNodeTypeLabelsConfiguration($nodeConfiguration);

self::assertEquals($expectedResult, $actualResult);
}


}
5 changes: 0 additions & 5 deletions Neos.Neos/Classes/Service/NodeTypeSchemaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ public function generateNodeTypeSchema()
foreach ($nodeTypes as $nodeTypeName => $nodeType) {
if ($nodeType->isAbstract() === false) {
$configuration = $nodeType->getFullConfiguration();
$configuration['properties'] = array_merge(
$configuration['properties'] ?? [],
$configuration['references'] ?? [],
);
unset($configuration['references']);
pKallert marked this conversation as resolved.
Show resolved Hide resolved
$schema['nodeTypes'][$nodeTypeName] = $configuration;
$schema['nodeTypes'][$nodeTypeName]['label'] = $nodeType->getLabel();
}
Expand Down
Loading