allow to use eel expressions in all Menu values
This commit is contained in:
parent
e0ff92c3fa
commit
fa3923d5e0
2 changed files with 43 additions and 0 deletions
|
@ -12,6 +12,8 @@ namespace DigiComp\Menu\MenuService;
|
||||||
* source code.
|
* source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Neos\Eel\EelEvaluatorInterface;
|
||||||
|
use Neos\Eel\Utility;
|
||||||
use Neos\Flow\Annotations as Flow;
|
use Neos\Flow\Annotations as Flow;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,6 +32,15 @@ class SettingsService implements ServiceInterface
|
||||||
*/
|
*/
|
||||||
protected array $items = [];
|
protected array $items = [];
|
||||||
|
|
||||||
|
#[Flow\InjectConfiguration(path: 'defaultEelContext', package: 'DigiComp.Menu')]
|
||||||
|
protected array $defaultContext = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Flow\Inject
|
||||||
|
* @var EelEvaluatorInterface
|
||||||
|
*/
|
||||||
|
protected $eelEvaluator;
|
||||||
|
|
||||||
public function getItems(string $forPath = null): \Iterator
|
public function getItems(string $forPath = null): \Iterator
|
||||||
{
|
{
|
||||||
if ($forPath) {
|
if ($forPath) {
|
||||||
|
@ -45,6 +56,21 @@ class SettingsService implements ServiceInterface
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
foreach ($items as $itemName => &$item) {
|
||||||
|
\array_walk_recursive(
|
||||||
|
$item,
|
||||||
|
fn (&$item) => $item =
|
||||||
|
\is_string($item) && \str_starts_with($item, '${') && \str_ends_with($item, '}')
|
||||||
|
? Utility::evaluateEelExpression(
|
||||||
|
$item,
|
||||||
|
$this->eelEvaluator,
|
||||||
|
[...$items, 'this' => $item, 'item' => $itemName],
|
||||||
|
$this->defaultContext
|
||||||
|
)
|
||||||
|
: $item
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return new \ArrayIterator($items);
|
return new \ArrayIterator($items);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
17
Configuration/Settings.yaml
Normal file
17
Configuration/Settings.yaml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
DigiComp:
|
||||||
|
Menu:
|
||||||
|
defaultEelContext:
|
||||||
|
String: 'Neos\Eel\Helper\StringHelper'
|
||||||
|
Array: 'Neos\Eel\Helper\ArrayHelper'
|
||||||
|
Date: 'Neos\Eel\Helper\DateHelper'
|
||||||
|
Configuration: 'Neos\Eel\Helper\ConfigurationHelper'
|
||||||
|
Math: 'Neos\Eel\Helper\MathHelper'
|
||||||
|
Json: 'Neos\Eel\Helper\JsonHelper'
|
||||||
|
Security: 'Neos\Eel\Helper\SecurityHelper'
|
||||||
|
Translation: 'Neos\Flow\I18n\EelHelper\TranslationHelper'
|
||||||
|
StaticResource: 'Neos\Flow\ResourceManagement\EelHelper\StaticResourceHelper'
|
||||||
|
Type: 'Neos\Eel\Helper\TypeHelper'
|
||||||
|
I18n: 'Neos\Flow\I18n\EelHelper\TranslationHelper'
|
||||||
|
File: 'Neos\Eel\Helper\FileHelper'
|
||||||
|
q: 'Neos\Eel\FlowQuery\FlowQuery::q'
|
||||||
|
BaseUri: 'Neos\Fusion\Eel\BaseUriHelper'
|
Loading…
Reference in a new issue