‪TYPO3CMS  9.5
AbstractNode.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 
18 use Psr\Log\LoggerAwareInterface;
19 use Psr\Log\LoggerAwareTrait;
22 
26 abstract class ‪AbstractNode implements ‪NodeInterface, LoggerAwareInterface
27 {
28  use LoggerAwareTrait;
29 
35  protected ‪$nodeFactory;
36 
42  protected ‪$data = [];
43 
49  protected ‪$defaultFieldInformation = [];
50 
57  protected ‪$defaultFieldControl = [];
58 
65  protected ‪$defaultFieldWizard = [];
66 
74  {
75  $this->data = ‪$data;
76  $this->nodeFactory = ‪$nodeFactory;
77  }
78 
84  abstract public function ‪render();
85 
93  protected function ‪initializeResultArray(): array
94  {
95  return [
96  'additionalJavaScriptPost' => [],
97  'additionalJavaScriptSubmit' => [],
98  'additionalHiddenFields' => [],
99  'additionalInlineLanguageLabelFiles' => [],
100  'stylesheetFiles' => [],
101  // can hold strings or arrays,
102  // string = requireJS module,
103  // array = requireJS module + callback e.g. array('TYPO3/Foo/Bar', 'function() {}')
104  'requireJsModules' => [],
105  'inlineData' => [],
106  'html' => '',
107  ];
108  }
109 
120  protected function ‪mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml = true): array
121  {
122  if ($mergeHtml && !empty($childReturn['html'])) {
123  $existing['html'] .= LF . $childReturn['html'];
124  }
125  foreach ($childReturn['additionalJavaScriptPost'] ?? [] as $value) {
126  $existing['additionalJavaScriptPost'][] = $value;
127  }
128  foreach ($childReturn['additionalJavaScriptSubmit'] ?? [] as $value) {
129  $existing['additionalJavaScriptSubmit'][] = $value;
130  }
131  foreach ($childReturn['additionalHiddenFields'] ?? [] as $value) {
132  $existing['additionalHiddenFields'][] = $value;
133  }
134  foreach ($childReturn['stylesheetFiles'] ?? [] as $value) {
135  $existing['stylesheetFiles'][] = $value;
136  }
137  foreach ($childReturn['requireJsModules'] ?? [] as $module) {
138  $existing['requireJsModules'][] = $module;
139  }
140  foreach ($childReturn['additionalInlineLanguageLabelFiles'] ?? [] as $inlineLanguageLabelFile) {
141  $existing['additionalInlineLanguageLabelFiles'][] = $inlineLanguageLabelFile;
142  }
143  if (!empty($childReturn['inlineData'])) {
144  $existingInlineData = $existing['inlineData'];
145  $childInlineData = $childReturn['inlineData'];
146  ‪ArrayUtility::mergeRecursiveWithOverrule($existingInlineData, $childInlineData);
147  $existing['inlineData'] = $existingInlineData;
148  }
149  return $existing;
150  }
151 
158  protected function ‪getValidationDataAsJsonString(array $config): string
159  {
160  $validationRules = [];
161  if (!empty($config['eval'])) {
162  $evalList = GeneralUtility::trimExplode(',', $config['eval'], true);
163  foreach ($evalList as $evalType) {
164  $validationRules[] = [
165  'type' => $evalType,
166  ];
167  }
168  }
169  if (!empty($config['range'])) {
170  $newValidationRule = [
171  'type' => 'range',
172  ];
173  if (!empty($config['range']['lower'])) {
174  $newValidationRule['lower'] = $config['range']['lower'];
175  }
176  if (!empty($config['range']['upper'])) {
177  $newValidationRule['upper'] = $config['range']['upper'];
178  }
179  $validationRules[] = $newValidationRule;
180  }
181  if (!empty($config['maxitems']) || !empty($config['minitems'])) {
182  $minItems = isset($config['minitems']) ? (int)$config['minitems'] : 0;
183  $maxItems = isset($config['maxitems']) ? (int)$config['maxitems'] : 99999;
184  $type = $config['type'] ?: 'range';
185  $validationRules[] = [
186  'type' => $type,
187  'minItems' => $minItems,
188  'maxItems' => $maxItems
189  ];
190  }
191  if (!empty($config['required'])) {
192  $validationRules[] = ['type' => 'required'];
193  }
194  return json_encode($validationRules);
195  }
196 }
‪TYPO3\CMS\Backend\Form\AbstractNode\$defaultFieldInformation
‪array $defaultFieldInformation
Definition: AbstractNode.php:46
‪TYPO3\CMS\Backend\Form
Definition: AbstractNode.php:3
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:115
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:88
‪TYPO3\CMS\Backend\Form\AbstractNode\$nodeFactory
‪NodeFactory $nodeFactory
Definition: AbstractNode.php:34
‪TYPO3\CMS\Backend\Form\AbstractNode\$defaultFieldControl
‪array $defaultFieldControl
Definition: AbstractNode.php:53
‪TYPO3\CMS\Backend\Form\AbstractNode\$defaultFieldWizard
‪array $defaultFieldWizard
Definition: AbstractNode.php:60
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:614
‪TYPO3\CMS\Backend\Form\AbstractNode\getValidationDataAsJsonString
‪string getValidationDataAsJsonString(array $config)
Definition: AbstractNode.php:153
‪TYPO3\CMS\Backend\Form\AbstractNode\__construct
‪__construct(NodeFactory $nodeFactory, array $data)
Definition: AbstractNode.php:68
‪TYPO3\CMS\Backend\Form\AbstractNode\$data
‪array $data
Definition: AbstractNode.php:40
‪TYPO3\CMS\Backend\Form\NodeInterface
Definition: NodeInterface.php:21
‪TYPO3\CMS\Backend\Form\NodeFactory
Definition: NodeFactory.php:36
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪TYPO3\CMS\Backend\Form\AbstractNode\render
‪array render()
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45