Last active
August 29, 2015 14:01
-
-
Save bwaidelich/cd696fb99c1882561e0b to your computer and use it in GitHub Desktop.
Fluid finisher for the TYPO3.Form package
This file contains hidden or 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 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; | |
| } | |
| } |
This file contains hidden or 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: | |
| 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' |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
Simple example using the YamlPersistenceManager (e.g. FormBuilder):