diff --git a/Classes/Core/Model/AbstractFinisher.php b/Classes/Core/Model/AbstractFinisher.php index d4585f7..75e7109 100644 --- a/Classes/Core/Model/AbstractFinisher.php +++ b/Classes/Core/Model/AbstractFinisher.php @@ -11,6 +11,10 @@ * source code. */ +use Neos\Eel\CompilingEvaluator; +use Neos\Eel\Utility; +use Neos\Eel\Utility as EelUtility; +use Neos\Flow\Annotations as Flow; use Neos\Utility\ObjectAccess; /** @@ -20,6 +24,19 @@ */ abstract class AbstractFinisher implements FinisherInterface { + + /** + * @Flow\Inject + * @var CompilingEvaluator + */ + protected $eelEvaluator; + + /** + * @Flow\InjectConfiguration + * @var array + */ + protected $settings; + /** * The options which have been set from the outside. Instead of directly * accessing them, you should rather use parseOption(). @@ -110,7 +127,20 @@ protected function parseOption($optionName) if (!is_string($option)) { return $option; } - $option = preg_replace_callback('/{([^}]+)}/', function ($match) use ($formRuntime) { + + $pregReplaceString = '/{([^}]+)}/'; + $parseEel = false; + $allowEelParsingForOptions = $this->parseOption('allowEelParsingForOptions'); + if (is_array($allowEelParsingForOptions) && key_exists($optionName, $allowEelParsingForOptions) && $allowEelParsingForOptions[$optionName] === true) { + $pregReplaceString = '/[{|\$]+([^}]+)}/'; + $parseEel = true; + } + + $option = preg_replace_callback($pregReplaceString, function ($match) use ($formRuntime, $parseEel) { + if ($parseEel && strpos($match[0], '${') === 0 && strpos($match[0], '}') === strlen($match[0]) - 1) { + return Utility::evaluateEelExpression($match[0], $this->eelEvaluator, EelUtility::getDefaultContextVariables($this->settings['defaultContext'])); + } + return ObjectAccess::getPropertyPath($formRuntime, $match[1]); }, $option); if ($option !== '') { diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index c5d4645..75ea8f0 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -1,6 +1,9 @@ Neos: Form: + defaultContext: + String: Neos\Eel\Helper\StringHelper + Configuration: Neos\Eel\Helper\ConfigurationHelper yamlPersistenceManager: savePath: '%FLOW_PATH_DATA%Forms/' supertypeResolver: diff --git a/Documentation/configuring-form-yaml.rst b/Documentation/configuring-form-yaml.rst index fa5da01..3e79ed4 100644 --- a/Documentation/configuring-form-yaml.rst +++ b/Documentation/configuring-form-yaml.rst @@ -83,11 +83,13 @@ The following YAML is stored as ``contact.yaml``: options: templatePathAndFilename: resource://AcmeCom.SomePackage/Private/Templates/Form/Contact.txt subject: '{subject}' - recipientAddress: 'info@acme.com' + recipientAddress: "${Configuration.setting('Foo.Bar.Site.Forms.contact.recipientAddress')}" # reads the recipient address from the configuration. See `allowEelParsingForOptions` recipientName: 'Acme Customer Care' senderAddress: '{email}' senderName: '{name}' format: plaintext + allowEelParsingForOptions: + recipientAddress: true # allow Eel parsing for these values (Security-Note: do not allow user-input options like `senderAddress` or `senderName`) .. note:: Instead of setting the ``templatePathAndFilename`` option to specify the Fluid template file for the EmailFinisher, the template source can also be set directly via the ``templateSource`` option.