Skip to content

Instantly share code, notes, and snippets.

@christian-fries
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christian-fries/eb3db022a125de5de9d6 to your computer and use it in GitHub Desktop.
Save christian-fries/eb3db022a125de5de9d6 to your computer and use it in GitHub Desktop.
EmailFinisher for TYPO3.Neos with configurable recipient
<?php
namespace LST\FormAdditions\Finishers;
/**
* @author Christian Fries
*/
class EmailFinisher extends \TYPO3\Form\Finishers\EmailFinisher {
/**
* Extends the functionality of the default parseOption() method
* by making recipientName and recipientAddress assignable in NodeType
*
* @param string $optionName
* @return mixed|string
*/
protected function parseOption($optionName) {
// check if recipient name is provided by the node
// use the recipientName defined in the form as fallback
if ($optionName === 'recipientName') {
$renderingOptions = $this->finisherContext->getFormRuntime()->getRenderingOptions();
$node = $renderingOptions['node'];
if ($node->hasProperty('recipientName')) {
$recipientName = $node->getProperty('recipientName');
if(!empty($recipientName)) {
return $recipientName;
}
}
}
// check if recipient address is provided by the node
// use the recipientAddress defined in the form as fallback
if ($optionName === 'recipientAddress') {
$renderingOptions = $this->finisherContext->getFormRuntime()->getRenderingOptions();
$node = $renderingOptions['node'];
if ($node->hasProperty('recipientAddress')) {
$recipientAddress = $node->getProperty('recipientAddress');
if(!empty($recipientAddress) && filter_var($recipientAddress, FILTER_VALIDATE_EMAIL)) {
return $recipientAddress;
}
}
}
return parent::parseOption($optionName);
}
}
{namespace form=TYPO3\Form\ViewHelpers}
<div{attributes -> f:format.raw()}>
<f:if condition="{formIdentifier}">
<f:then>
<form:render persistenceIdentifier="{formIdentifier}" presetName="{presetName}" overrideConfiguration="{renderingOptions:{node: node}}" />
</f:then>
<f:else>
<p>Please select a valid Form identifier in the inspector</p>
</f:else>
</f:if>
</div>
'TYPO3.Neos.NodeTypes:Form':
ui:
inspector:
groups:
customForm:
label: 'Form'
position: 1
properties:
recipientName:
type: string
ui:
label: 'Recipient Name'
inspector:
group: 'customForm'
recipientAddress:
type: string
ui:
label: 'Recipient Email Address'
inspector:
group: 'customForm'
prototype(TYPO3.Neos.NodeTypes:Form) {
templatePath = 'resource://LST.FormAdditions/Private/Templates/NodeTypes/Form.html'
}
TYPO3:
Neos:
typoScript:
autoInclude:
'LST.FormAdditions': TRUE
Form:
presets:
default:
finisherPresets:
'LST.FormAdditions:Email':
implementationClassName: 'LST\FormAdditions\Finishers\EmailFinisher'
@christian-fries
Copy link
Author

Tested with Typo3 Neos 1.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment