‪TYPO3CMS  9.5
ConfirmationFinisher.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
25 
48 {
49 
53  protected ‪$defaultOptions = [
54  'message' => 'The form has been submitted.',
55  'contentElementUid' => 0,
56  'typoscriptObjectPath' => 'lib.tx_form.contentElementRendering'
57  ];
58 
62  protected ‪$typoScriptSetup = [];
63 
67  protected ‪$configurationManager;
68 
73  {
74  $this->configurationManager = ‪$configurationManager;
75  $this->typoScriptSetup = $this->configurationManager->‪getConfiguration(‪ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
76  }
77 
81  public function ‪injectContentObjectRenderer(‪ContentObjectRenderer $contentObjectRenderer)
82  {
83  $this->contentObjectRenderer = $contentObjectRenderer;
84  }
85 
94  protected function ‪executeInternal()
95  {
96  $contentElementUid = $this->‪parseOption('contentElementUid');
97  $typoscriptObjectPath = $this->‪parseOption('typoscriptObjectPath');
98  if (!empty($contentElementUid)) {
99  $pathSegments = GeneralUtility::trimExplode('.', $typoscriptObjectPath);
100  $lastSegment = array_pop($pathSegments);
101  $setup = ‪$this->typoScriptSetup;
102  foreach ($pathSegments as $segment) {
103  if (!array_key_exists($segment . '.', $setup)) {
104  throw new ‪FinisherException(
105  sprintf('TypoScript object path "%s" does not exist', $typoscriptObjectPath),
106  1489238980
107  );
108  }
109  $setup = $setup[$segment . '.'];
110  }
111  $this->contentObjectRenderer->start([$contentElementUid], '');
112  $this->contentObjectRenderer->setCurrentVal((string)$contentElementUid);
113  $message = $this->contentObjectRenderer->cObjGetSingle($setup[$lastSegment], $setup[$lastSegment . '.'], $lastSegment);
114  } else {
115  $message = $this->‪parseOption('message');
116  }
117 
118  $standaloneView = $this->‪initializeStandaloneView(
119  $this->finisherContext->getFormRuntime()
120  );
121 
122  $standaloneView->assignMultiple([
123  'message' => $message,
124  'isPreparedMessage' => !empty($contentElementUid),
125  ]);
126 
127  return $standaloneView->render();
128  }
129 
135  protected function ‪initializeStandaloneView(‪FormRuntime $formRuntime): ‪StandaloneView
136  {
137  $standaloneView = $this->objectManager->get(StandaloneView::class);
138 
139  if (!isset($this->options['templateName'])) {
140  throw new ‪FinisherException(
141  'The option "templateName" must be set for the ConfirmationFinisher.',
142  1521573955
143  );
144  }
145 
146  $standaloneView->setTemplate($this->options['templateName']);
147  $standaloneView->getTemplatePaths()->fillFromConfigurationArray($this->options);
148 
149  if (isset($this->options['variables']) && is_array($this->options['variables'])) {
150  $standaloneView->assignMultiple($this->options['variables']);
151  }
152 
153  $standaloneView->assign('form', $formRuntime);
154  $standaloneView->assign('finisherVariableProvider', $this->finisherContext->getFinisherVariableProvider());
155 
156  $standaloneView->getRenderingContext()
157  ->getViewHelperVariableContainer()
158  ->addOrUpdate(RenderRenderableViewHelper::class, 'formRuntime', $formRuntime);
159 
160  return $standaloneView;
161  }
162 }
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\injectContentObjectRenderer
‪injectContentObjectRenderer(ContentObjectRenderer $contentObjectRenderer)
Definition: ConfirmationFinisher.php:78
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormRuntime.php:97
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\injectConfigurationManager
‪injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
Definition: ConfirmationFinisher.php:69
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\initializeStandaloneView
‪StandaloneView initializeStandaloneView(FormRuntime $formRuntime)
Definition: ConfirmationFinisher.php:132
‪TYPO3
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:22
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\getConfiguration
‪array getConfiguration($configurationType, $extensionName=null, $pluginName=null)
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher
Definition: ConfirmationFinisher.php:48
‪TYPO3\CMS\Form\Domain\Finishers
Definition: AbstractFinisher.php:3
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\$configurationManager
‪ConfigurationManagerInterface $configurationManager
Definition: ConfirmationFinisher.php:64
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher
Definition: AbstractFinisher.php:35
‪TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException
Definition: FinisherException.php:24
‪TYPO3\CMS\Form\ViewHelpers\RenderRenderableViewHelper
Definition: RenderRenderableViewHelper.php:37
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_FULL_TYPOSCRIPT
‪const CONFIGURATION_TYPE_FULL_TYPOSCRIPT
Definition: ConfigurationManagerInterface.php:25
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormSession.php:3
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:91
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher\parseOption
‪string array null parseOption(string $optionName)
Definition: AbstractFinisher.php:155
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\executeInternal
‪string executeInternal()
Definition: ConfirmationFinisher.php:91
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\$defaultOptions
‪array $defaultOptions
Definition: ConfirmationFinisher.php:52
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\$typoScriptSetup
‪array $typoScriptSetup
Definition: ConfirmationFinisher.php:60