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