Skip to content

Commit

Permalink
Merge pull request #82 from Flowpack/task/costmeticAdjustmentsForVers…
Browse files Browse the repository at this point in the history
…ion2

TASK: Costmetic adjustments for version2
  • Loading branch information
mhsdesign authored Jun 21, 2024
2 parents b9891bc + 853ffc2 commit 7900bd7
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 120 deletions.
4 changes: 2 additions & 2 deletions Classes/Application/Command/NodeTemplateCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class NodeTemplateCommandController extends CommandController
* Dump the node tree structure into a NodeTemplate YAML structure.
* References to Nodes and non-primitive property values are commented out in the YAML.
*
* @param string $startingNodeId specified root node of the node tree
* @param string $workspaceName
* @param string $startingNodeId specified root node of the node tree.
* @param string $workspaceName custom workspace to dump from. Defaults to 'live'.
* @return void
*/
public function createFromNodeSubtreeCommand(string $startingNodeId, string $workspaceName = 'live'): void
Expand Down
6 changes: 3 additions & 3 deletions Classes/Domain/NodeTemplateDumper/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
class Comment
{
/**
* @psalm-var \Closure(string $indentation, string $propertyName): string $renderFunction
* @var \Closure(string $indentation, string $propertyName): string $renderFunction
*/
private \Closure $renderFunction;

/**
* @psalm-param \Closure(string $indentation, string $propertyName): string $renderFunction
* @param \Closure(string $indentation, string $propertyName): string $renderFunction
*/
private function __construct(\Closure $renderFunction)
{
$this->renderFunction = $renderFunction;
}

/**
* @psalm-param \Closure(string $indentation, string $propertyName): string $renderFunction
* @param \Closure(string $indentation, string $propertyName): string $renderFunction
*/
public static function fromRenderer($renderFunction): self
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class EelEvaluationService
/**
* Evaluate an Eel expression.
*
* @param $contextVariables array<string, mixed> additional context for eel expressions
* @param array<string, mixed> $contextVariables additional context for eel expressions
* @return mixed The result of the evaluated Eel expression
* @throws ParserException|\Exception
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class TemplateConfigurationProcessor
protected $eelEvaluationService;

/**
* @psalm-param array<string, mixed> $configuration
* @psalm-param array<string, mixed> $evaluationContext
* @param array<string, mixed> $configuration
* @param array<string, mixed> $evaluationContext
* @param ProcessingErrors $caughtEvaluationExceptions
* @return RootTemplate
*/
Expand Down Expand Up @@ -145,9 +145,9 @@ private function createTemplateFromTemplatePart(TemplatePart $templatePart): Tem
}

/**
* @psalm-param mixed $rawConfigurationValue
* @psalm-param array<string, mixed> $evaluationContext
* @psalm-return mixed
* @param mixed $rawConfigurationValue
* @param array<string, mixed> $evaluationContext
* @return mixed
* @throws \Neos\Eel\ParserException|\Exception
*/
private function preprocessConfigurationValue($rawConfigurationValue, array $evaluationContext)
Expand Down
22 changes: 11 additions & 11 deletions Classes/Domain/TemplateConfiguration/TemplatePart.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TemplatePart

/**
* @psalm-readonly
* @psalm-var \Closure(mixed $value, array<string, mixed> $evaluationContext): mixed
* @var \Closure(mixed $value, array<string, mixed> $evaluationContext): mixed
*/
private \Closure $configurationValueProcessor;

Expand All @@ -40,9 +40,9 @@ class TemplatePart
private ProcessingErrors $processingErrors;

/**
* @psalm-param array<string, mixed> $configuration
* @psalm-param array<string, mixed> $evaluationContext
* @psalm-param \Closure(mixed $value, array<string, mixed> $evaluationContext): mixed $configurationValueProcessor
* @param array<string, mixed> $configuration
* @param array<string, mixed> $evaluationContext
* @param \Closure(mixed $value, array<string, mixed> $evaluationContext): mixed $configurationValueProcessor
* @throws StopBuildingTemplatePartException
*/
private function __construct(
Expand All @@ -61,9 +61,9 @@ private function __construct(
}

/**
* @psalm-param array<string, mixed> $configuration
* @psalm-param array<string, mixed> $evaluationContext
* @psalm-param \Closure(mixed $value, array<string, mixed> $evaluationContext): mixed $configurationValueProcessor
* @param array<string, mixed> $configuration
* @param array<string, mixed> $evaluationContext
* @param \Closure(mixed $value, array<string, mixed> $evaluationContext): mixed $configurationValueProcessor
* @throws StopBuildingTemplatePartException
*/
public static function createRoot(
Expand Down Expand Up @@ -102,7 +102,7 @@ public function getFullPathToConfiguration(): array
}

/**
* @psalm-param string|list<string> $configurationPath
* @param string|list<string> $configurationPath
* @throws StopBuildingTemplatePartException
*/
public function withConfigurationByConfigurationPath($configurationPath): self
Expand All @@ -117,7 +117,7 @@ public function withConfigurationByConfigurationPath($configurationPath): self
}

/**
* @psalm-param array<string, mixed> $evaluationContext
* @param array<string, mixed> $evaluationContext
*/
public function withMergedEvaluationContext(array $evaluationContext): self
{
Expand All @@ -134,7 +134,7 @@ public function withMergedEvaluationContext(array $evaluationContext): self
}

/**
* @psalm-param string|list<string> $configurationPath
* @param string|list<string> $configurationPath
* @return mixed
* @throws StopBuildingTemplatePartException
*/
Expand Down Expand Up @@ -185,7 +185,7 @@ public function getRawConfiguration($configurationPath)
}

/**
* @psalm-param string|list<string> $configurationPath
* @param string|list<string> $configurationPath
*/
public function hasConfiguration($configurationPath): bool
{
Expand Down
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Neos Node Templates

When using Neos CMS as an editor, you often work with nested node structures that
When using Neos CMS as an editor, you often work with nested node structures that
have to be created manually. This packages aims at easing the editing workflow by
automatically creating helpful child nodes and making useful modifications to node
automatically creating helpful child nodes and making useful modifications to node
properties when creating new nodes in the Neos UI.

In contrast to child nodes that are defined in the regular node type definition
(which cannot be removed by the editor), all modifications that are made when a
(which cannot be removed by the editor), all modifications that are made when a
template is applied can be changed or removed by the editor.

The desired node structure is defined in a declarative way in the NodeTypes.yaml
Expand Down Expand Up @@ -89,7 +89,7 @@ You can also access data from the node creation dialog if you use the
ui:
showInCreationDialog: true
'cardTitle':
type: string:
type: string
label: 'Card Title'
options:
template:
Expand Down Expand Up @@ -129,7 +129,7 @@ templates) from being applied, its most common use case is conditional child nod
### Loops

Loops can be used to create multiple child nodes. You can use ``withItems`` to define the items
of the loop. When using EEL, be sure to return an array. The current item is available in EEL
of the loop. When using EEL, be sure to return an array. The current item is available in EEL
expressions as the ``item`` context variable.

The following example creates three different text child nodes in the main content collection:
Expand Down Expand Up @@ -259,17 +259,22 @@ My.NodeType:Bar (depends on "data" context)

The standalone validation should detect errors and prevents editors having to deal with these errors at runtime.

For more complex templates, which are dependent on the node creation data, it is recommended to write separate tests. Currently, errors in templates depending on the data context will only be treated as warning, as they are probably not an issue at runtime.
For more complex templates, which are dependent on the node creation data, it is recommended to write separate tests. Currently, errors in templates depending on the data context will only be treated as warning, as they are probably not an issue at runtime.

## Create template from node subtree

When creating a more complex node template (to create multiple pages and content elements) it can be helpful to take the current node subtree from your workspace as reference.
For this case you can use the command:

```sh
flow nodeTemplate:createFromNodeSubtree <nodeIdentifier>
flow nodeTemplate:createFromNodeSubtree <starting node id>
```

- `--starting-node-id`: specified root node of the node tree

**options:**
- `--workspace-name`: custom workspace to dump from. Defaults to 'live'.

It will give you the output similar to the yaml example above.
References to Nodes and non-primitive property values are commented out in the YAML.

Expand Down
22 changes: 16 additions & 6 deletions Tests/Functional/AbstractNodeTemplateTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Neos\ContentRepository\Domain\Model\Workspace;
use Neos\ContentRepository\Domain\Repository\ContentDimensionRepository;
use Neos\ContentRepository\Domain\Repository\WorkspaceRepository;
use Neos\ContentRepository\Domain\Service\Context;
use Neos\ContentRepository\Domain\Service\ContextFactoryInterface;
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
use Neos\Flow\Tests\FunctionalTestCase;
Expand Down Expand Up @@ -43,10 +42,11 @@ abstract class AbstractNodeTemplateTestCase extends FunctionalTestCase

private NodeTypeManager $nodeTypeManager;

private Context $subgraph;

private string $fixturesDir;

/** @deprecated please use {@see self::getObject()} instead */
protected $objectManager;

public function setUp(): void
{
parent::setUp();
Expand Down Expand Up @@ -82,6 +82,17 @@ public function tearDown(): void
$this->objectManager->forgetInstance(NodeTypeManager::class);
}

/**
* @template T of object
* @param class-string<T> $className
*
* @return T
*/
final protected function getObject(string $className): object
{
return $this->objectManager->get($className);
}

private function setupContentRepository(): void
{
// Create an environment to create nodes.
Expand All @@ -98,10 +109,9 @@ private function setupContentRepository(): void

$this->persistenceManager->persistAll();
$this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class);
$this->subgraph = $this->contextFactory->create(['workspaceName' => 'live']);

$rootNode = $this->subgraph->getRootNode();
$subgraph = $this->contextFactory->create(['workspaceName' => 'live']);

$rootNode = $subgraph->getRootNode();

$sitesRootNode = $rootNode->createNode('sites');
$testSiteNode = $sitesRootNode->createNode('test-site');
Expand Down
12 changes: 9 additions & 3 deletions Tests/Functional/FakeNodeTypeManagerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,25 @@

use Neos\ContentRepository\Domain\Service\NodeTypeManager;
use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
use Neos\Utility\Arrays;
use Symfony\Component\Yaml\Yaml;

/**
* @property ObjectManagerInterface $objectManager
* @property NodeTypeManager $nodeTypeManager
*/
trait FakeNodeTypeManagerTrait
{
/**
* @template T of object
* @param class-string<T> $className
*
* @return T
*/
abstract protected function getObject(string $className): object;

private function loadFakeNodeTypes(): void
{
$configuration = $this->objectManager->get(ConfigurationManager::class)->getConfiguration('NodeTypes');
$configuration = $this->getObject(ConfigurationManager::class)->getConfiguration('NodeTypes');

$fileIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__ . '/Features'));

Expand Down
12 changes: 0 additions & 12 deletions Tests/Functional/Features/Exceptions/ExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,6 @@ public function exceptionsAreCaughtAndPartialTemplateIsNotBuild(): void

$this->assertLastCreatedTemplateMatchesSnapshot('OnlyExceptions');

// self::assertSame([
// [
// 'message' => 'Template for "WithOneEvaluationException" was not applied. Only Node /sites/test-site/homepage/main/new-node@live[Flowpack.NodeTemplates:Content.WithOneEvaluationException] was created.',
// 'severity' => 'ERROR'
// ],
// [
// 'message' => 'Expression "${\'left open" in "childNodes.abort.when" | EelException(The EEL expression "${\'left open" was not a valid EEL expression. Perhaps you forgot to wrap it in ${...}?, 1410441849)',
// 'severity' => 'ERROR'
// ]
// ], $this->getMessagesOfFeedbackCollection());


$this->assertCaughtExceptionsMatchesSnapshot('OnlyExceptions');
$this->assertNodeDumpAndTemplateDumpMatchSnapshot('OnlyExceptions', $createdNode);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ public function itMatchesSnapshot1(): void
$this->createFakeNode('some-node-id');
$this->createFakeNode('other-node-id');

$resource = $this->objectManager->get(ResourceManager::class)->importResource(__DIR__ . '/image.png');
$resource = $this->getObject(ResourceManager::class)->importResource(__DIR__ . '/image.png');

$asset = new Asset($resource);
ObjectAccess::setProperty($asset, 'Persistence_Object_Identifier', 'c228200e-7472-4290-9936-4454a5b5692a', true);
$this->objectManager->get(AssetRepository::class)->add($asset);
$this->getObject(AssetRepository::class)->add($asset);

$resource2 = $this->objectManager->get(ResourceManager::class)->importResource(__DIR__ . '/image.png');
$resource2 = $this->getObject(ResourceManager::class)->importResource(__DIR__ . '/image.png');

$image = new Image($resource2);
ObjectAccess::setProperty($image, 'Persistence_Object_Identifier', 'c8ae9f9f-dd11-4373-bf42-4bf31ec5bd19', true);
$this->objectManager->get(ImageRepository::class)->add($image);
$this->getObject(ImageRepository::class)->add($image);

$createdNode = $this->createNodeInto(
$this->homePageMainContentCollectionNode,
Expand Down
Loading

0 comments on commit 7900bd7

Please sign in to comment.