67 lines
2.1 KiB
PHP
67 lines
2.1 KiB
PHP
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace DigiComp\AttachmentViewUtility;
|
||
|
|
||
|
use Neos\Eel\CompilingEvaluator;
|
||
|
use Neos\Eel\Context;
|
||
|
use Neos\Eel\Helper\ArrayHelper;
|
||
|
use Neos\Eel\Helper\StringHelper;
|
||
|
use Neos\Flow\Annotations as Flow;
|
||
|
use Neos\Flow\I18n\EelHelper\TranslationHelper;
|
||
|
use Neos\FluidAdaptor\View\TemplateView;
|
||
|
use Neos\Utility\TypeHandling;
|
||
|
|
||
|
trait EelFilenameTrait
|
||
|
{
|
||
|
protected string $eelExpressionOptionKey = 'filenameEelExpression';
|
||
|
|
||
|
protected function addOptionFilenameEelExpression(): void
|
||
|
{
|
||
|
if (\property_exists($this, 'supportedOptions')) {
|
||
|
$this->supportedOptions['filenameEelExpression'] = [
|
||
|
null,
|
||
|
'Callable which creates a filename from variables',
|
||
|
'string',
|
||
|
true,
|
||
|
];
|
||
|
} else {
|
||
|
throw new \RuntimeException('supported option could not be set', 1697552694);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
protected function getAttachmentName(): string
|
||
|
{
|
||
|
if ($this instanceof TemplateView) {
|
||
|
$variables = $this->getRenderingContext()->getVariableProvider()->getAll();
|
||
|
} elseif (\property_exists($this, 'variables')) {
|
||
|
$variables = $this->variables;
|
||
|
} else {
|
||
|
throw new \RuntimeException(
|
||
|
'No variables can be detected for this kind of view: ' . TypeHandling::getTypeForValue($this),
|
||
|
1697550214
|
||
|
);
|
||
|
}
|
||
|
if (!\property_exists($this, 'options')) {
|
||
|
throw new \RuntimeException('Your view options could not be found', 1697550440);
|
||
|
}
|
||
|
$expression = $this->options[$this->eelExpressionOptionKey];
|
||
|
$context = new Context(\array_merge($variables, [
|
||
|
'Array' => new ArrayHelper(),
|
||
|
'String' => new StringHelper(),
|
||
|
'Translation' => new TranslationHelper(),
|
||
|
]));
|
||
|
$this->emitFilenameEelExpressionContext($context);
|
||
|
return (new CompilingEvaluator())->evaluate($expression, $context);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @SuppressWarnings("unused")
|
||
|
*/
|
||
|
#[Flow\Signal]
|
||
|
protected function emitFilenameEelExpressionContext(Context $context): void
|
||
|
{
|
||
|
}
|
||
|
}
|