I’m responsing to myself for possible other readers:
Solution 1 = Custom Finisher implementation:
In my case I added a new finisher, extending the mailfinisher.
Short summary:
class MailToContactPersonFinisher extends EmailFinisher
{
const FORMAT_PLAINTEXT = 'plaintext';
const FORMAT_HTML = 'html';
/**
* @var array
*/
protected $defaultOptions = [
'recipientName' => '',
'senderName' => '',
'format' => self::FORMAT_HTML,
'attachUploads' => true
];
/**
* Executes this finisher
* @see AbstractFinisher::execute()
*
* @throws FinisherException
*/
protected function executeInternal()
{
/** @var FormRuntime $formRuntime */
$formRuntime = $this->finisherContext->getFormRuntime();
$standaloneView = $this->initializeStandaloneView($formRuntime);
if ($formRuntime->getResponse()->getRequest()->hasArgument('contactPerson')) {
$id = $formRuntime->getResponse()->getRequest()->getArgument('contactPerson');
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var ContactPersonRepository $repository */
$repository = $objectManager->get(ContactPersonRepository::class);
/** @var ContactPerson $contactPerson */
$contactPerson = $repository->findByUid($id);
$this->setOption('subject', 'FOOBAR');
$this->setOption('recipientAddress', $contactPerson->getEmail());
$this->setOption('senderAddress', $formRuntime->getRequest()->getArgument('email'));
$this->setOption('senderName', $formRuntime->getRequest()->getArgument('name'));
parent::executeInternal();
}
}
}
Solution 2 = Loading and manipulating the yaml configuration and build the form:
/** @var FormPersistenceManagerInterface $formPersistanceManager */
$formPersistanceManager = $this->objectManager->get(FormPersistenceManagerInterface::class);
$formConfiguration = $formPersistanceManager->load('EXT:path_to_ext/Resources/Private/Forms/NameOfForm.yaml');
$formDefinition->createFinisher(
'EmailToReceiver',
[
'subject' => 'Dies ist meine Mail',
'recipientAddress' => $contactPerson->getEmail(),
'recipientName' => $contactPerson->getName(),
'senderAddress' => '***@example.xy',
'senderName' => 'Max Mustermann',
]
);
/** @var FormRuntime $form */
$form = $formDefinition->bind($this->request, $this->response);
$this->view->assign('form', $form->render());
In my use case solution 1 was perfect. Solution 2 is in my opinion more like a workaround, a bit more complicated, but allows more manipulation and customization.
With a custom finisher, I did not have the chance to influence other finishers. For example, if the form factory has other mail finishers, I can’t interrupt sending them all. Or is there a way to stop all other finishers from a single finisher? Something like $this->finisherContext->getFormRuntime()->stopFinisherPropgation(); ?
Mikel
Post by MikelHi all,
I am implementing the new form framework into an own extension.
- Model „ContactPerson“ has a property „mailAdress“
- Model „ContactPerson“ has a form implemented on it’s showAction
- The form has a „basic setup“ with common fields for all implementations, configured by yaml
- The finisher should be overwritten, when the form is rendered by the showAction of ContactPerson
What is best practise to add a custom finisher in relation to a given model? By „hooking in“ to „initializeFormElement“? Or with a custom finisher? Or with passing a configuration array to form render viewhelper and override the form configuration?
Any hints / discussion / snippets appreciated.
Mikel
_______________________________________________
TYPO3-english mailing list
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-english