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