‪TYPO3CMS  11.5
AbstractNode.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 
20 use Psr\Log\LoggerAwareInterface;
21 use Psr\Log\LoggerAwareTrait;
24 
28 abstract class ‪AbstractNode implements ‪NodeInterface, LoggerAwareInterface
29 {
30  use LoggerAwareTrait;
31 
37  protected ‪$nodeFactory;
38 
44  protected array ‪$data = [];
45 
51  protected ‪$defaultFieldInformation = [];
52 
59  protected ‪$defaultFieldControl = [];
60 
67  protected ‪$defaultFieldWizard = [];
68 
76  {
77  $this->data = ‪$data;
78  $this->nodeFactory = ‪$nodeFactory;
79  }
80 
86  abstract public function ‪render();
87 
95  protected function ‪initializeResultArray(): array
96  {
97  return [
98  // @todo deprecate inline JavaScript in TYPO3 v12.0
99  'additionalJavaScriptPost' => [],
100  // @todo deprecate additionalHiddenFields in TYPO3 v12.0 - this return key is essentially
101  // useless. Elements can simply submit their hidden HTML fields in the html key.
102  'additionalHiddenFields' => [],
103  'additionalInlineLanguageLabelFiles' => [],
104  'stylesheetFiles' => [],
105  // can hold strings or arrays,
106  // string = requireJS module,
107  // array = requireJS module + callback e.g. array('TYPO3/Foo/Bar', 'function() {}')
108  'requireJsModules' => [],
109  'inlineData' => [],
110  'html' => '',
111  ];
112  }
113 
124  protected function ‪mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml = true): array
125  {
126  if ($mergeHtml && !empty($childReturn['html'])) {
127  $existing['html'] .= LF . $childReturn['html'];
128  }
129  // @todo deprecate inline JavaScript in TYPO3 v12.0
130  foreach ($childReturn['additionalJavaScriptPost'] ?? [] as $value) {
131  $existing['additionalJavaScriptPost'][] = $value;
132  }
133  foreach ($childReturn['additionalHiddenFields'] ?? [] as $value) {
134  $existing['additionalHiddenFields'][] = $value;
135  }
136  foreach ($childReturn['stylesheetFiles'] ?? [] as $value) {
137  $existing['stylesheetFiles'][] = $value;
138  }
139  foreach ($childReturn['requireJsModules'] ?? [] as $module) {
140  $existing['requireJsModules'][] = $module;
141  }
142  foreach ($childReturn['additionalInlineLanguageLabelFiles'] ?? [] as $inlineLanguageLabelFile) {
143  $existing['additionalInlineLanguageLabelFiles'][] = $inlineLanguageLabelFile;
144  }
145  if (!empty($childReturn['inlineData'])) {
146  $existingInlineData = $existing['inlineData'];
147  $childInlineData = $childReturn['inlineData'];
148  ‪ArrayUtility::mergeRecursiveWithOverrule($existingInlineData, $childInlineData);
149  $existing['inlineData'] = $existingInlineData;
150  }
151  return $existing;
152  }
153 
160  protected function ‪getValidationDataAsJsonString(array $config): string
161  {
162  $validationRules = [];
163  if (!empty($config['eval'])) {
164  $evalList = ‪GeneralUtility::trimExplode(',', $config['eval'] ?? '', true);
165  foreach ($evalList as $evalType) {
166  $validationRules[] = [
167  'type' => $evalType,
168  ];
169  }
170  }
171  if (!empty($config['range'])) {
172  $newValidationRule = [
173  'type' => 'range',
174  ];
175  if (!empty($config['range']['lower'])) {
176  $newValidationRule['lower'] = $config['range']['lower'];
177  }
178  if (!empty($config['range']['upper'])) {
179  $newValidationRule['upper'] = $config['range']['upper'];
180  }
181  $validationRules[] = $newValidationRule;
182  }
183  if (!empty($config['maxitems']) || !empty($config['minitems'])) {
184  $minItems = isset($config['minitems']) ? (int)$config['minitems'] : 0;
185  $maxItems = isset($config['maxitems']) ? (int)$config['maxitems'] : 99999;
186  $type = $config['type'] ?: 'range';
187  $validationRules[] = [
188  'type' => $type,
189  'minItems' => $minItems,
190  'maxItems' => $maxItems,
191  ];
192  }
193  if (!empty($config['required'])) {
194  $validationRules[] = ['type' => 'required'];
195  }
196  return json_encode($validationRules);
197  }
198 }
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:999
‪TYPO3\CMS\Backend\Form\AbstractNode\$defaultFieldInformation
‪array $defaultFieldInformation
Definition: AbstractNode.php:49
‪TYPO3\CMS\Backend\Form
Definition: AbstractNode.php:18
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:120
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:91
‪TYPO3\CMS\Backend\Form\AbstractNode\$nodeFactory
‪NodeFactory $nodeFactory
Definition: AbstractNode.php:36
‪TYPO3\CMS\Backend\Form\AbstractNode\$defaultFieldControl
‪array $defaultFieldControl
Definition: AbstractNode.php:56
‪TYPO3\CMS\Backend\Form\AbstractNode\$defaultFieldWizard
‪array $defaultFieldWizard
Definition: AbstractNode.php:63
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:654
‪TYPO3\CMS\Backend\Form\AbstractNode\getValidationDataAsJsonString
‪string getValidationDataAsJsonString(array $config)
Definition: AbstractNode.php:156
‪TYPO3\CMS\Backend\Form\AbstractNode\__construct
‪__construct(NodeFactory $nodeFactory, array $data)
Definition: AbstractNode.php:71
‪TYPO3\CMS\Backend\Form\AbstractNode\$data
‪array $data
Definition: AbstractNode.php:43
‪TYPO3\CMS\Backend\Form\NodeInterface
Definition: NodeInterface.php:22
‪TYPO3\CMS\Backend\Form\NodeFactory
Definition: NodeFactory.php:37
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪TYPO3\CMS\Backend\Form\AbstractNode\render
‪array render()
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50