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