‪TYPO3CMS  ‪main
FinisherOptionGenerator.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 
23 
30 {
36  public function ‪__invoke(string $_, $__, array $matches)
37  {
38  [, $optionKey] = $matches;
39 
40  $finisherIdentifier = $this->converterDto->getFinisherIdentifier();
41  $finisherDefinitionFromSetup = $this->converterDto->getFinisherDefinitionFromSetup();
42  $finisherDefinitionFromFormDefinition = $this->converterDto->getFinisherDefinitionFromFormDefinition();
43 
44  try {
45  $elementConfiguration = ‪ArrayUtility::getValueByPath(
46  $finisherDefinitionFromSetup['FormEngine']['elements'],
47  $optionKey,
48  '.'
49  );
50  } catch (‪MissingArrayPathException $exception) {
51  return;
52  }
53 
54  // use the option value from the ext:form setup from the current finisher as default value
55  try {
56  $optionValue = ‪ArrayUtility::getValueByPath(
57  $finisherDefinitionFromSetup,
58  sprintf('options.%s', $optionKey),
59  '.'
60  );
61  } catch (‪MissingArrayPathException $exception) {
62  $optionValue = null;
63  }
64 
65  // use the option value from the form definition from the current finisher (if exists) as default value
66  try {
67  $optionValue = ‪ArrayUtility::getValueByPath(
68  $finisherDefinitionFromFormDefinition,
69  sprintf('options.%s', $optionKey),
70  '.'
71  );
72  } catch (‪MissingArrayPathException $exception) {
73  }
74 
75  if (isset($elementConfiguration['config'])) {
76  $elementConfiguration['config']['default'] = $optionValue;
77  }
78 
79  $languageService = $this->‪getLanguageService();
80  $elementConfiguration['label'] = (string)($elementConfiguration['label'] ?? '');
81  if (empty($optionValue)) {
82  $optionValue = $languageService->sL('LLL:EXT:form/Resources/Private/Language/Database.xlf:empty');
83  } elseif (is_array($optionValue)) {
84  $optionValue = implode(',', $optionValue);
85  }
86  $elementConfiguration['label'] .= sprintf(' (%s: "%s")', $languageService->sL('LLL:EXT:form/Resources/Private/Language/Database.xlf:default'), $optionValue);
87 
88  $sheetElements = $this->converterDto->getResult();
89  $sheetElements['settings.finishers.' . $finisherIdentifier . '.' . $optionKey] = $elementConfiguration;
90 
91  $this->converterDto->setResult($sheetElements);
92  }
93 
95  {
96  return ‪$GLOBALS['LANG'];
97  }
98 }
‪TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException
Definition: MissingArrayPathException.php:27
‪TYPO3\CMS\Form\Domain\Configuration\FlexformConfiguration\Processors\AbstractProcessor
Definition: AbstractProcessor.php:24
‪TYPO3\CMS\Core\Utility\ArrayUtility\getValueByPath
‪static getValueByPath(array $array, array|string $path, string $delimiter='/')
Definition: ArrayUtility.php:176
‪TYPO3\CMS\Form\Domain\Configuration\FlexformConfiguration\Processors\FinisherOptionGenerator
Definition: FinisherOptionGenerator.php:30
‪TYPO3\CMS\Form\Domain\Configuration\FlexformConfiguration\Processors\FinisherOptionGenerator\__invoke
‪__invoke(string $_, $__, array $matches)
Definition: FinisherOptionGenerator.php:36
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:26
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Form\Domain\Configuration\FlexformConfiguration\Processors
Definition: AbstractProcessor.php:18
‪TYPO3\CMS\Form\Domain\Configuration\FlexformConfiguration\Processors\FinisherOptionGenerator\getLanguageService
‪getLanguageService()
Definition: FinisherOptionGenerator.php:94