Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Allow Eel-Helper in AbstractFinisher for parseOption() #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion Classes/Core/Model/AbstractFinisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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().
Expand Down Expand Up @@ -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 !== '') {
Expand Down
3 changes: 3 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

Neos:
Form:
defaultContext:
String: Neos\Eel\Helper\StringHelper
Configuration: Neos\Eel\Helper\ConfigurationHelper
yamlPersistenceManager:
savePath: '%FLOW_PATH_DATA%Forms/'
supertypeResolver:
Expand Down
4 changes: 3 additions & 1 deletion Documentation/configuring-form-yaml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]'
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.
Expand Down