You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Documentation/01_PresentationObjectsAndComponents.md
+101-1Lines changed: 101 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@
8
8
9
9
# 1. PresentationObjects and Components
10
10
11
-
> **Hint:** This section describes the manual creation of PresentationObjectsand PresentationObject components. Both patterns can also be scaffolded by the [Kickstarter](./05_Kickstarter.md).
11
+
> **Hint:** This section describes the manual creation of PresentationObjects, Pseudo-Enums and PresentationObject components. All these patterns can also be scaffolded by the [Kickstarter](./05_Kickstarter.md).
12
12
13
13
In this tutorial, we're going to write a PresentationObject for an image component. Our image consists of a `src`, an `alt` and an optional `title` property.
Now instead of having a string typed property in our headline, we can model it as follows:
226
+
227
+
```php
228
+
<?php declare(strict_types=1);
229
+
namespace Acme\Site\Presentation\Block\Headline;
230
+
231
+
interface HeadlineInterface
232
+
{
233
+
public function getType(): HeadlineType;
234
+
235
+
public function getContent(): string;
236
+
}
237
+
```
238
+
239
+
> **Hint:** Pseudo-enums can also be used in Neos' inspector select box editor. Please refer to [Integration Recipes](./04_IntegrationRecipes.md) to learn how it is done.
Copy file name to clipboardExpand all lines: Documentation/04_IntegrationRecipes.md
+133Lines changed: 133 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,6 +80,139 @@ Resolves URIs with the special `asset://` and `node://` protocols.
80
80
| $rawLinkUri | string | The string containing the URI ||
81
81
| $subgraph |[ContentContext](https://github.com/neos/neos-development-collection/blob/master/Neos.Neos/Classes/Domain/Service/ContentContext.php)| A reference content context required to resolve `node://` URIs ||
82
82
83
+
## The EnumProvider
84
+
85
+
All pseudo-enums implementing the PseudoEnumInterface can be provided to the inspector or the Fusion runtime using the PseudoEnumProvider.
86
+
This makes the enum itself the single source of discrete values a node or presentation object property may have, obsoleting value adjustments in Fusion, configuration etc.
87
+
88
+
As an example, we use the following pseudo-enum:
89
+
90
+
```php
91
+
<?php declare(strict_types=1);
92
+
namespace Acme\Site\Presentation\Block\Headline;
93
+
94
+
use Neos\Flow\Annotations as Flow;
95
+
use PackageFactory\AtomicFusion\PresentationObjects\Domain\Enum\PseudoEnumInterface;
96
+
97
+
/**
98
+
* @Flow\Proxy(false)
99
+
*/
100
+
final class HeadlineType implements PseudoEnumInterface
101
+
{
102
+
const TYPE_H1 = 'h1';
103
+
const TYPE_H2 = 'h2';
104
+
const TYPE_H3 = 'h3';
105
+
106
+
private string $value;
107
+
108
+
private function __construct(string $value)
109
+
{
110
+
$this->value = $value;
111
+
}
112
+
113
+
public static function h1(): self
114
+
{
115
+
return new self(self::TYPE_H1);
116
+
}
117
+
118
+
public static function h2(): self
119
+
{
120
+
return new self(self::TYPE_H2);
121
+
}
122
+
123
+
public static function h3(): self
124
+
{
125
+
return new self(self::TYPE_H3);
126
+
}
127
+
128
+
/**
129
+
* @return array|self[]
130
+
*/
131
+
public static function cases(): array
132
+
{
133
+
return [
134
+
new self(self::TYPE_H1),
135
+
new self(self::TYPE_H2),
136
+
new self(self::TYPE_H3)
137
+
];
138
+
}
139
+
140
+
public function getValue(): string
141
+
{
142
+
return $this->value;
143
+
}
144
+
145
+
public function __toString(): string
146
+
{
147
+
return $this->value;
148
+
}
149
+
}
150
+
151
+
```
152
+
153
+
### As a node type postprocessor
154
+
155
+
Due to cacheability and thus improved performance, it is recommended to use the EnumProvider's node type postprocessor capabilities to make the enum's cases available in the Inspector.
156
+
157
+
When we now declare our NodeType property, we do this as follows:
The initial values are left empty and will be completely populated by the postprocessor. While the postprocessor is the same for all enums, there are two configuration options available:
178
+
* enumName: The enum's fully qualified PHP class name
179
+
* propertyNames: A list of property names to apply this enum's values to
180
+
181
+
### As a data source
182
+
183
+
If for some reason the postprocessor does not suffice, there is also the possibility to use the provider as a data source.
184
+
Be aware that though more flexible, data sources are called on each load of the inspector, impacting performance.
185
+
The provider can be used as a data source as follows:
0 commit comments