TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
AbstractFinisher.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Form\Domain\Finishers;
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 
22 
29 abstract class AbstractFinisher implements FinisherInterface
30 {
31 
35  protected $objectManager;
36 
40  protected $finisherIdentifier = '';
41 
48  protected $options = [];
49 
57  protected $defaultOptions = [];
58 
62  protected $finisherContext;
63 
68  public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
69  {
70  $this->objectManager = $objectManager;
71  }
72 
78  public function setOptions(array $options)
79  {
80  $this->options = $options;
81  }
82 
91  public function setOption(string $optionName, $optionValue)
92  {
93  $this->options[$optionName] = $optionValue;
94  }
95 
103  final public function execute(FinisherContext $finisherContext)
104  {
105  $this->finisherIdentifier = (new \ReflectionClass($this))->getShortName();
106  $this->finisherContext = $finisherContext;
107  $this->executeInternal();
108  }
109 
118  abstract protected function executeInternal();
119 
132  protected function parseOption(string $optionName)
133  {
134  if ($optionName === 'translation') {
135  return null;
136  }
137 
138  try {
139  $optionValue = ArrayUtility::getValueByPath($this->options, $optionName, '.');
140  } catch (\RuntimeException $exception) {
141  $optionValue = null;
142  }
143  try {
144  $defaultValue = ArrayUtility::getValueByPath($this->defaultOptions, $optionName, '.');
145  } catch (\RuntimeException $exception) {
146  $defaultValue = null;
147  }
148 
149  if ($optionValue === null && $defaultValue !== null) {
150  $optionValue = $defaultValue;
151  }
152 
153  if ($optionValue === null) {
154  return null;
155  }
156 
157  if (is_array($optionValue)) {
158  return $optionValue;
159  }
160 
161  $formRuntime = $this->finisherContext->getFormRuntime();
162  $optionToCompare = $optionValue;
163 
164  // You can encapsulate a option value with {}.
165  // This enables you to access every getable property from the
166  // TYPO3\CMS\Form\Domain\Runtime.
167  //
168  // For example: {formState.formValues.<elemenIdentifier>}
169  // This is equal to "$formRuntime->getFormState()->getFormValues()[<elemenIdentifier>]"
170  $optionValue = preg_replace_callback('/{([^}]+)}/', function ($match) use ($formRuntime) {
171  return ObjectAccess::getPropertyPath($formRuntime, $match[1]);
172  }, $optionValue);
173 
174  if ($optionToCompare === $optionValue) {
175 
176  // This is just a shortcut for a {formState.formValues.<elementIdentifier>} notation.
177  // If one of the finisher option values is equal
178  // to a identifier from the form definition then
179  // the value of the submitted form element is used
180  // insteed.
181  // Lets say you have a textfield in your form with the
182  // identifier "Text1". If you put "Text1"
183  // in the email finisher option "subject" then the submited value
184  // from the "Text1" element is used as the email subject.
185  $formValues = $this->finisherContext->getFormValues();
186  if (!is_bool($optionValue) && array_key_exists($optionValue, $formValues)) {
187  $optionValue = $formRuntime[$optionValue];
188  }
189  }
190 
191  if (isset($this->options['translation']['translationFile'])) {
192  $optionValue = TranslationService::getInstance()->translateFinisherOption(
193  $formRuntime,
194  $this->finisherIdentifier,
195  $optionName,
196  $optionValue,
197  $this->options['translation']
198  );
199  }
200 
201  if (empty($optionValue)) {
202  if ($defaultValue !== null) {
203  $optionValue = $defaultValue;
204  }
205  }
206  return $optionValue;
207  }
208 
212  protected function getTypoScriptFrontendController()
213  {
214  return $GLOBALS['TSFE'];
215  }
216 }
static getPropertyPath($subject, $propertyPath)
static getValueByPath(array $array, $path, $delimiter= '/')
setOption(string $optionName, $optionValue)
injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']