‪TYPO3CMS  10.4
IsCreatablePropertyCollectionElementExtractor.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 
22 
27 {
28 
34  public function ‪__invoke(string $_, $value, array $matches)
35  {
36  [, $formElementType, $formEditorIndex] = $matches;
37 
38  if (
39  $value !== 'Inspector-FinishersEditor'
40  && $value !== 'Inspector-ValidatorsEditor'
41  && $value !== 'Inspector-RequiredValidatorEditor'
42  ) {
43  return;
44  }
45 
46  $propertyCollectionName = $value === 'Inspector-FinishersEditor' ? 'finishers' : 'validators';
47 
48  $result = $this->extractorDto->getResult();
49 
50  if (
51  $value === 'Inspector-FinishersEditor'
52  || $value === 'Inspector-ValidatorsEditor'
53  ) {
54  $selectOptionsPath = implode(
55  '.',
56  [
57  'formElementsDefinition',
58  $formElementType,
59  'formEditor',
60  'editors',
61  $formEditorIndex,
62  'selectOptions',
63  ]
64  );
65  if (!‪ArrayUtility::isValidPath($this->extractorDto->getPrototypeConfiguration(), $selectOptionsPath, '.')) {
66  return;
67  }
68  $selectOptions = ‪ArrayUtility::getValueByPath(
69  $this->extractorDto->getPrototypeConfiguration(),
70  $selectOptionsPath,
71  '.'
72  );
73  foreach ($selectOptions as $selectOption) {
74  $validatorIdentifier = $selectOption['value'] ?? '';
75  if (empty($validatorIdentifier)) {
76  continue;
77  }
78 
79  $result['formElements'][$formElementType]['collections'][$propertyCollectionName][$validatorIdentifier]['creatable'] = true;
80  }
81  } else {
82  $validatorIdentifierPath = implode(
83  '.',
84  [
85  'formElementsDefinition',
86  $formElementType,
87  'formEditor',
88  'editors',
89  $formEditorIndex,
90  'validatorIdentifier',
91  ]
92  );
93  if (!‪ArrayUtility::isValidPath($this->extractorDto->getPrototypeConfiguration(), $validatorIdentifierPath, '.')) {
94  return;
95  }
96  $validatorIdentifier = ‪ArrayUtility::getValueByPath(
97  $this->extractorDto->getPrototypeConfiguration(),
98  $validatorIdentifierPath,
99  '.'
100  );
101  $result['formElements'][$formElementType]['collections'][$propertyCollectionName][$validatorIdentifier]['creatable'] = true;
102  }
103 
104  $this->extractorDto->setResult($result);
105  }
106 }
‪TYPO3\CMS\Form\Domain\Configuration\FrameworkConfiguration\Extractors\AbstractExtractor
Definition: AbstractExtractor.php:24
‪TYPO3\CMS\Core\Utility\ArrayUtility\isValidPath
‪static bool isValidPath(array $array, $path, $delimiter='/')
Definition: ArrayUtility.php:144
‪TYPO3\CMS\Form\Domain\Configuration\FrameworkConfiguration\Extractors\PropertyCollectionElement\IsCreatablePropertyCollectionElementExtractor\__invoke
‪__invoke(string $_, $value, array $matches)
Definition: IsCreatablePropertyCollectionElementExtractor.php:34
‪TYPO3\CMS\Core\Utility\ArrayUtility\getValueByPath
‪static mixed getValueByPath(array $array, $path, $delimiter='/')
Definition: ArrayUtility.php:180
‪TYPO3\CMS\Form\Domain\Configuration\FrameworkConfiguration\Extractors\PropertyCollectionElement
Definition: IsCreatablePropertyCollectionElementExtractor.php:18
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪TYPO3\CMS\Form\Domain\Configuration\FrameworkConfiguration\Extractors\PropertyCollectionElement\IsCreatablePropertyCollectionElementExtractor
Definition: IsCreatablePropertyCollectionElementExtractor.php:27