Last active
August 29, 2015 14:15
-
-
Save christian-fries/eb3db022a125de5de9d6 to your computer and use it in GitHub Desktop.
EmailFinisher for TYPO3.Neos with configurable recipient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prototype(TYPO3.Neos.NodeTypes:Form) { | |
templatePath = 'resource://LST.FormAdditions/Private/Templates/NodeTypes/Form.html' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TYPO3: | |
Neos: | |
typoScript: | |
autoInclude: | |
'LST.FormAdditions': TRUE | |
Form: | |
presets: | |
default: | |
finisherPresets: | |
'LST.FormAdditions:Email': | |
implementationClassName: 'LST\FormAdditions\Finishers\EmailFinisher' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested with Typo3 Neos 1.2