setOptions( * [ * 'message' => 'foo', * ] * ); * $formDefinition->addFinisher($confirmationFinisher); * // ... * * Scope: frontend */ class ConfirmationFinisher extends AbstractFinisher { /** * @var array */ protected $defaultOptions = [ 'message' => 'The form has been submitted.', 'contentElementUid' => 0, 'typoscriptObjectPath' => 'lib.tx_form.contentElementRendering', ]; public function __construct( private readonly ExtbaseConfigurationManagerInterface $extbaseConfigurationManager, private readonly ViewFactoryInterface $viewFactory, ) {} /** * @throws FinisherException */ protected function executeInternal(): string { $options = $this->options; if (!isset($options['templateName']) || !is_string($options['templateName'])) { throw new FinisherException( 'The option "templateName" must be set for the ConfirmationFinisher.', 1521573955 ); } $contentElementUid = $this->parseOption('contentElementUid'); $typoscriptObjectPath = $this->parseOption('typoscriptObjectPath'); $typoscriptObjectPath = is_string($typoscriptObjectPath) ? $typoscriptObjectPath : ''; if (!empty($contentElementUid)) { $pathSegments = GeneralUtility::trimExplode('.', $typoscriptObjectPath); $lastSegment = array_pop($pathSegments); $setup = $this->extbaseConfigurationManager->getConfiguration(ExtbaseConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT); foreach ($pathSegments as $segment) { if (!array_key_exists($segment . '.', $setup)) { throw new FinisherException( sprintf('TypoScript object path "%s" does not exist', $typoscriptObjectPath), 1489238980 ); } $setup = $setup[$segment . '.']; } $contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class); $contentObjectRenderer->setRequest($this->finisherContext->getRequest()->withoutAttribute('extbase')); $contentObjectRenderer->start([$contentElementUid]); $contentObjectRenderer->setCurrentVal((string)$contentElementUid); $message = $contentObjectRenderer->cObjGetSingle($setup[$lastSegment], $setup[$lastSegment . '.'], $lastSegment); } else { $message = $this->parseOption('message'); } $formRuntime = $this->finisherContext->getFormRuntime(); $viewFactoryData = new ViewFactoryData( templateRootPaths: is_array($options['templateRootPaths'] ?? null) ? $options['templateRootPaths'] : [], partialRootPaths: is_array($options['partialRootPaths'] ?? null) ? $options['partialRootPaths'] : [], layoutRootPaths: is_array($options['layoutRootPaths'] ?? null) ? $options['layoutRootPaths'] : [], request: $this->finisherContext->getRequest(), ); $view = $this->viewFactory->create($viewFactoryData); if ($view instanceof FluidViewAdapter) { $view->getRenderingContext()->getViewHelperVariableContainer() ->addOrUpdate(RenderRenderableViewHelper::class, 'formRuntime', $formRuntime); } if (is_array($this->options['variables'] ?? null)) { $view->assignMultiple($this->options['variables']); } $view->assignMultiple([ 'form' => $formRuntime, 'finisherVariableProvider' => $this->finisherContext->getFinisherVariableProvider(), 'message' => $message, 'isPreparedMessage' => !empty($contentElementUid), ]); return $view->render($options['templateName']); } }