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