‪TYPO3CMS  10.4
ConfirmationFinisher.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
27 
50 {
51 
55  protected ‪$defaultOptions = [
56  'message' => 'The form has been submitted.',
57  'contentElementUid' => 0,
58  'typoscriptObjectPath' => 'lib.tx_form.contentElementRendering'
59  ];
60 
64  protected ‪$typoScriptSetup = [];
65 
69  protected ‪$configurationManager;
70 
74  protected ‪$contentObjectRenderer;
75 
80  {
81  $this->configurationManager = ‪$configurationManager;
82  $this->typoScriptSetup = $this->configurationManager->‪getConfiguration(‪ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
83  }
84 
89  {
90  $this->contentObjectRenderer = ‪$contentObjectRenderer;
91  }
92 
101  protected function ‪executeInternal()
102  {
103  $contentElementUid = $this->‪parseOption('contentElementUid');
104  $typoscriptObjectPath = $this->‪parseOption('typoscriptObjectPath');
105  $typoscriptObjectPath = is_string($typoscriptObjectPath) ? $typoscriptObjectPath : '';
106  if (!empty($contentElementUid)) {
107  $pathSegments = ‪GeneralUtility::trimExplode('.', $typoscriptObjectPath);
108  $lastSegment = array_pop($pathSegments);
109  $setup = ‪$this->typoScriptSetup;
110  foreach ($pathSegments as $segment) {
111  if (!array_key_exists($segment . '.', $setup)) {
112  throw new ‪FinisherException(
113  sprintf('TypoScript object path "%s" does not exist', $typoscriptObjectPath),
114  1489238980
115  );
116  }
117  $setup = $setup[$segment . '.'];
118  }
119  $this->contentObjectRenderer->start([$contentElementUid], '');
120  $this->contentObjectRenderer->setCurrentVal((string)$contentElementUid);
121  $message = $this->contentObjectRenderer->cObjGetSingle($setup[$lastSegment], $setup[$lastSegment . '.'], $lastSegment);
122  } else {
123  $message = $this->‪parseOption('message');
124  }
125 
126  $standaloneView = $this->‪initializeStandaloneView(
127  $this->finisherContext->getFormRuntime()
128  );
129 
130  $standaloneView->assignMultiple([
131  'message' => $message,
132  'isPreparedMessage' => !empty($contentElementUid),
133  ]);
134 
135  return $standaloneView->render();
136  }
137 
143  protected function ‪initializeStandaloneView(FormRuntime $formRuntime): StandaloneView
144  {
145  $standaloneView = $this->objectManager->get(StandaloneView::class);
146 
147  if (!isset($this->options['templateName'])) {
148  throw new FinisherException(
149  'The option "templateName" must be set for the ConfirmationFinisher.',
150  1521573955
151  );
152  }
153 
154  $standaloneView->setTemplate($this->options['templateName']);
155  $standaloneView->getTemplatePaths()->fillFromConfigurationArray($this->options);
156 
157  if (isset($this->options['variables']) && is_array($this->options['variables'])) {
158  $standaloneView->assignMultiple($this->options['variables']);
159  }
160 
161  $standaloneView->assign('form', $formRuntime);
162  $standaloneView->assign('finisherVariableProvider', $this->finisherContext->getFinisherVariableProvider());
163 
164  $standaloneView->getRenderingContext()
165  ->getViewHelperVariableContainer()
166  ->addOrUpdate(RenderRenderableViewHelper::class, 'formRuntime', $formRuntime);
167 
168  return $standaloneView;
169  }
170 }
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\$contentObjectRenderer
‪ContentObjectRenderer $contentObjectRenderer
Definition: ConfirmationFinisher.php:70
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\injectContentObjectRenderer
‪injectContentObjectRenderer(ContentObjectRenderer $contentObjectRenderer)
Definition: ConfirmationFinisher.php:84
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormRuntime.php:103
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\initializeStandaloneView
‪StandaloneView initializeStandaloneView(FormRuntime $formRuntime)
Definition: ConfirmationFinisher.php:139
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:28
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher
Definition: ConfirmationFinisher.php:50
‪TYPO3\CMS\Form\Domain\Finishers
Definition: AbstractFinisher.php:22
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\$configurationManager
‪ConfigurationManagerInterface $configurationManager
Definition: ConfirmationFinisher.php:66
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher
Definition: AbstractFinisher.php:41
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\injectConfigurationManager
‪injectConfigurationManager(ConfigurationManagerInterface $configurationManager)
Definition: ConfirmationFinisher.php:75
‪TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException
Definition: FinisherException.php:26
‪TYPO3\CMS\Form\ViewHelpers\RenderRenderableViewHelper
Definition: RenderRenderableViewHelper.php:41
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\getConfiguration
‪array getConfiguration(string $configurationType, ?string $extensionName=null, ?string $pluginName=null)
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_FULL_TYPOSCRIPT
‪const CONFIGURATION_TYPE_FULL_TYPOSCRIPT
Definition: ConfigurationManagerInterface.php:31
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormSession.php:18
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:97
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher\parseOption
‪string array null parseOption(string $optionName)
Definition: AbstractFinisher.php:161
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\executeInternal
‪string executeInternal()
Definition: ConfirmationFinisher.php:97
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\$defaultOptions
‪array $defaultOptions
Definition: ConfirmationFinisher.php:54
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\$typoScriptSetup
‪array $typoScriptSetup
Definition: ConfirmationFinisher.php:62