‪TYPO3CMS  ‪main
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 {
54  protected ‪$defaultOptions = [
55  'message' => 'The form has been submitted.',
56  'contentElementUid' => 0,
57  'typoscriptObjectPath' => 'lib.tx_form.contentElementRendering',
58  ];
59 
60  protected array ‪$typoScriptSetup = [];
61 
63 
65 
67  {
68  $this->configurationManager = ‪$configurationManager;
69  $this->typoScriptSetup = $this->configurationManager->‪getConfiguration(‪ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
70  }
71 
73  {
74  $this->contentObjectRenderer = ‪$contentObjectRenderer;
75  }
76 
85  protected function ‪executeInternal()
86  {
87  $contentElementUid = $this->‪parseOption('contentElementUid');
88  $typoscriptObjectPath = $this->‪parseOption('typoscriptObjectPath');
89  $typoscriptObjectPath = is_string($typoscriptObjectPath) ? $typoscriptObjectPath : '';
90  if (!empty($contentElementUid)) {
91  $pathSegments = ‪GeneralUtility::trimExplode('.', $typoscriptObjectPath);
92  $lastSegment = array_pop($pathSegments);
94  foreach ($pathSegments as $segment) {
95  if (!array_key_exists($segment . '.', $setup)) {
96  throw new ‪FinisherException(
97  sprintf('TypoScript object path "%s" does not exist', $typoscriptObjectPath),
98  1489238980
99  );
100  }
101  $setup = $setup[$segment . '.'];
102  }
103  $this->contentObjectRenderer->setRequest($this->finisherContext->getRequest());
104  $this->contentObjectRenderer->start([$contentElementUid]);
105  $this->contentObjectRenderer->setCurrentVal((string)$contentElementUid);
106  $message = $this->contentObjectRenderer->cObjGetSingle($setup[$lastSegment], $setup[$lastSegment . '.'], $lastSegment);
107  } else {
108  $message = $this->‪parseOption('message');
109  }
110 
111  $standaloneView = $this->‪initializeStandaloneView(
112  $this->finisherContext->getFormRuntime()
113  );
114 
115  $standaloneView->assignMultiple([
116  'message' => $message,
117  'isPreparedMessage' => !empty($contentElementUid),
118  ]);
119 
120  return $standaloneView->render();
121  }
122 
126  protected function ‪initializeStandaloneView(FormRuntime $formRuntime): StandaloneView
127  {
128  $standaloneView = GeneralUtility::makeInstance(StandaloneView::class);
129  $standaloneView->setRequest($this->finisherContext->getRequest());
130 
131  if (!isset($this->options['templateName'])) {
132  throw new FinisherException(
133  'The option "templateName" must be set for the ConfirmationFinisher.',
134  1521573955
135  );
136  }
137 
138  $standaloneView->setTemplate($this->options['templateName']);
139  $standaloneView->getTemplatePaths()->fillFromConfigurationArray($this->options);
140 
141  if (isset($this->options['variables']) && is_array($this->options['variables'])) {
142  $standaloneView->assignMultiple($this->options['variables']);
143  }
144 
145  $standaloneView->assign('form', $formRuntime);
146  $standaloneView->assign('finisherVariableProvider', $this->finisherContext->getFinisherVariableProvider());
147 
148  $standaloneView->getRenderingContext()
149  ->getViewHelperVariableContainer()
150  ->addOrUpdate(RenderRenderableViewHelper::class, 'formRuntime', $formRuntime);
151 
152  return $standaloneView;
153  }
154 }
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\$contentObjectRenderer
‪ContentObjectRenderer $contentObjectRenderer
Definition: ConfirmationFinisher.php:63
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\injectContentObjectRenderer
‪injectContentObjectRenderer(ContentObjectRenderer $contentObjectRenderer)
Definition: ConfirmationFinisher.php:71
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormRuntime.php:106
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:28
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\initializeStandaloneView
‪initializeStandaloneView(FormRuntime $formRuntime)
Definition: ConfirmationFinisher.php:125
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher
Definition: ConfirmationFinisher.php:50
‪TYPO3\CMS\Form\Domain\Finishers
Definition: AbstractFinisher.php:22
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher\parseOption
‪string array int null parseOption(string $optionName)
Definition: AbstractFinisher.php:139
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\$configurationManager
‪ConfigurationManagerInterface $configurationManager
Definition: ConfirmationFinisher.php:61
‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher
Definition: AbstractFinisher.php:41
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\injectConfigurationManager
‪injectConfigurationManager(ConfigurationManagerInterface $configurationManager)
Definition: ConfirmationFinisher.php:65
‪TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException
Definition: FinisherException.php:25
‪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\Fluid\View\StandaloneView
Definition: StandaloneView.php:30
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormSession.php:18
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:102
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\executeInternal
‪string executeInternal()
Definition: ConfirmationFinisher.php:84
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\$defaultOptions
‪array $defaultOptions
Definition: ConfirmationFinisher.php:53
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode(string $delim, string $string, bool $removeEmptyValues=false, int $limit=0)
Definition: GeneralUtility.php:822
‪TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher\$typoScriptSetup
‪array $typoScriptSetup
Definition: ConfirmationFinisher.php:59