‪TYPO3CMS  9.5
FinisherOptionGenerator.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 
22 
29 {
33  protected ‪$languageService;
34 
39  {
40  parent::__construct(‪$converterDto);
41 
42  $this->languageService = GeneralUtility::makeInstance(LanguageService::class);
43  $this->languageService->includeLLFile('EXT:form/Resources/Private/Language/Database.xlf');
44  }
45 
51  public function ‪__invoke(string $_, $__, array $matches)
52  {
53  [, $optionKey] = $matches;
54 
55  $finisherIdentifier = $this->converterDto->getFinisherIdentifier();
56  $finisherDefinitionFromSetup = $this->converterDto->getFinisherDefinitionFromSetup();
57  $finisherDefinitionFromFormDefinition = $this->converterDto->getFinisherDefinitionFromFormDefinition();
58 
59  try {
60  $elementConfiguration = ‪ArrayUtility::getValueByPath(
61  $finisherDefinitionFromSetup['FormEngine']['elements'],
62  $optionKey,
63  '.'
64  );
65  } catch (‪MissingArrayPathException $exception) {
66  return;
67  }
68 
69  // use the option value from the ext:form setup from the current finisher as default value
70  try {
71  $optionValue = ‪ArrayUtility::getValueByPath(
72  $finisherDefinitionFromSetup,
73  sprintf('options.%s', $optionKey),
74  '.'
75  );
76  } catch (‪MissingArrayPathException $exception) {
77  $optionValue = null;
78  }
79 
80  // use the option value from the form definition from the current finisher (if exists) as default value
81  try {
82  $optionValue = ‪ArrayUtility::getValueByPath(
83  $finisherDefinitionFromFormDefinition,
84  sprintf('options.%s', $optionKey),
85  '.'
86  );
87  } catch (‪MissingArrayPathException $exception) {
88  }
89 
90  if (empty($optionValue)) {
91  $elementConfiguration['label'] .= sprintf(' (%s: "%s")', $this->languageService->getLL('default'), $this->languageService->getLL('empty'));
92  } else {
93  $elementConfiguration['label'] .= sprintf(' (%s: "' . $optionValue . '")', $this->languageService->getLL('default'));
94  }
95 
96  $elementConfiguration['config']['default'] = $optionValue;
97 
98  $sheetElements = $this->converterDto->getResult();
99  $sheetElements['settings.finishers.' . $finisherIdentifier . '.' . $optionKey]['TCEforms'] = $elementConfiguration;
100 
101  $this->converterDto->setResult($sheetElements);
102  }
103 }
‪TYPO3\CMS\Form\Domain\Configuration\FlexformConfiguration\Processors\FinisherOptionGenerator\$languageService
‪TYPO3 CMS Core Localization LanguageService $languageService
Definition: FinisherOptionGenerator.php:32
‪TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException
Definition: MissingArrayPathException.php:26
‪TYPO3\CMS\Form\Domain\Configuration\FlexformConfiguration\Processors\ProcessorDto
Definition: ProcessorDto.php:24
‪TYPO3\CMS\Form\Domain\Configuration\FlexformConfiguration\Processors\AbstractProcessor
Definition: AbstractProcessor.php:22
‪TYPO3\CMS\Core\Utility\ArrayUtility\getValueByPath
‪static mixed getValueByPath(array $array, $path, $delimiter='/')
Definition: ArrayUtility.php:179
‪TYPO3\CMS\Form\Domain\Configuration\FlexformConfiguration\Processors\FinisherOptionGenerator\__construct
‪__construct(ProcessorDto $converterDto)
Definition: FinisherOptionGenerator.php:37
‪TYPO3\CMS\Form\Domain\Configuration\FlexformConfiguration\Processors\FinisherOptionGenerator
Definition: FinisherOptionGenerator.php:29
‪TYPO3\CMS\Form\Domain\Configuration\FlexformConfiguration\Processors\FinisherOptionGenerator\__invoke
‪__invoke(string $_, $__, array $matches)
Definition: FinisherOptionGenerator.php:50
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Form\Domain\Configuration\FlexformConfiguration\Processors
Definition: AbstractProcessor.php:3
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Form\Domain\Configuration\FlexformConfiguration\Processors\AbstractProcessor\$converterDto
‪ProcessorDto $converterDto
Definition: AbstractProcessor.php:25