Skip to content

Instantly share code, notes, and snippets.

@bwaidelich
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save bwaidelich/cd696fb99c1882561e0b to your computer and use it in GitHub Desktop.

Select an option

Save bwaidelich/cd696fb99c1882561e0b to your computer and use it in GitHub Desktop.
Fluid finisher for the TYPO3.Form package
<?php
namespace Your\Package\Form\Finishers;
use TYPO3\Flow\Utility\Arrays;
use TYPO3\Fluid\View\StandaloneView;
use TYPO3\Form\Core\Model\AbstractFinisher;
use TYPO3\Form\Core\Runtime\FormRuntime;
use TYPO3\Form\Exception\FinisherException;
/**
* Custom finisher for the TYPO3.Form package that displays a Fluid template
*/
class FluidFinisher extends AbstractFinisher {
/**
* @return void
*/
protected function executeInternal() {
$formRuntime = $this->finisherContext->getFormRuntime();
$standaloneView = $this->initializeStandaloneView($formRuntime);
$response = $formRuntime->getResponse();
$response->setContent($standaloneView->render());
}
/**
* @param FormRuntime $formRuntime
* @return StandaloneView
* @throws FinisherException
*/
protected function initializeStandaloneView(FormRuntime $formRuntime) {
$standaloneView = new StandaloneView($formRuntime->getRequest());
if (isset($this->options['templatePathAndFilename'])) {
$standaloneView->setTemplatePathAndFilename($this->options['templatePathAndFilename']);
} elseif (isset($this->options['templateSource'])) {
$standaloneView->setTemplateSource($this->options['templateSource']);
} else {
throw new FinisherException('One of the options "templatePathAndFilename" or "templateSource" must be set for the FluidFinisher.', 1400687692);
}
if (isset($this->options['partialRootPath'])) {
$standaloneView->setPartialRootPath($this->options['partialRootPath']);
}
if (isset($this->options['layoutRootPath'])) {
$standaloneView->setLayoutRootPath($this->options['layoutRootPath']);
}
$variables = $formRuntime->getFormState()->getFormValues();
if (isset($this->options['variables'])) {
$variables = Arrays::arrayMergeRecursiveOverrule($variables, $this->options['variables']);
}
$standaloneView->assignMultiple($variables);
return $standaloneView;
}
}
TYPO3:
Form:
presets:
# use a different preset name if you don't want to add the finisher to the default preset
'default':
# finisher definition
finisherPresets:
'Your.Package:Fluid':
implementationClassName: 'Your\Package\Form\Finishers\FluidFinisher'
@bwaidelich
Copy link
Author

Usage:

Simple example using the YamlPersistenceManager (e.g. FormBuilder):

type: 'TYPO3.Form:Form'
identifier: finisherwithlink
label: 'Finisher with link'
finishers:
    -
        identifier: 'Your.Package:Fluid'
        options:
            templateSource: 'The value of a1 is {a1}! <f:link.action action="index">Back</f:link.action>'
renderingOptions:
    submitButtonLabel: ''
renderables:
    -
        type: 'TYPO3.Form:Page'
        identifier: page1
        label: 'Page 1'
        renderables:
            -
                type: 'TYPO3.Form:SingleLineText'
                identifier: a1
                label: A1
                properties:
                    placeholder: ''
                defaultValue: ''

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