‪TYPO3CMS  10.4
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 ‪$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  'additionalJavaScriptPost' => [],
99  'additionalHiddenFields' => [],
100  'additionalInlineLanguageLabelFiles' => [],
101  'stylesheetFiles' => [],
102  // can hold strings or arrays,
103  // string = requireJS module,
104  // array = requireJS module + callback e.g. array('TYPO3/Foo/Bar', 'function() {}')
105  'requireJsModules' => [],
106  'inlineData' => [],
107  'html' => '',
108  ];
109  }
110 
121  protected function ‪mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml = true): array
122  {
123  if ($mergeHtml && !empty($childReturn['html'])) {
124  $existing['html'] .= LF . $childReturn['html'];
125  }
126  foreach ($childReturn['additionalJavaScriptPost'] ?? [] as $value) {
127  $existing['additionalJavaScriptPost'][] = $value;
128  }
129  foreach ($childReturn['additionalHiddenFields'] ?? [] as $value) {
130  $existing['additionalHiddenFields'][] = $value;
131  }
132  foreach ($childReturn['stylesheetFiles'] ?? [] as $value) {
133  $existing['stylesheetFiles'][] = $value;
134  }
135  foreach ($childReturn['requireJsModules'] ?? [] as $module) {
136  $existing['requireJsModules'][] = $module;
137  }
138  foreach ($childReturn['additionalInlineLanguageLabelFiles'] ?? [] as $inlineLanguageLabelFile) {
139  $existing['additionalInlineLanguageLabelFiles'][] = $inlineLanguageLabelFile;
140  }
141  if (!empty($childReturn['inlineData'])) {
142  $existingInlineData = $existing['inlineData'];
143  $childInlineData = $childReturn['inlineData'];
144  ‪ArrayUtility::mergeRecursiveWithOverrule($existingInlineData, $childInlineData);
145  $existing['inlineData'] = $existingInlineData;
146  }
147  return $existing;
148  }
149 
156  protected function ‪getValidationDataAsJsonString(array $config): string
157  {
158  $validationRules = [];
159  if (!empty($config['eval'])) {
160  $evalList = ‪GeneralUtility::trimExplode(',', $config['eval'], true);
161  foreach ($evalList as $evalType) {
162  $validationRules[] = [
163  'type' => $evalType,
164  ];
165  }
166  }
167  if (!empty($config['range'])) {
168  $newValidationRule = [
169  'type' => 'range',
170  ];
171  if (!empty($config['range']['lower'])) {
172  $newValidationRule['lower'] = $config['range']['lower'];
173  }
174  if (!empty($config['range']['upper'])) {
175  $newValidationRule['upper'] = $config['range']['upper'];
176  }
177  $validationRules[] = $newValidationRule;
178  }
179  if (!empty($config['maxitems']) || !empty($config['minitems'])) {
180  $minItems = isset($config['minitems']) ? (int)$config['minitems'] : 0;
181  $maxItems = isset($config['maxitems']) ? (int)$config['maxitems'] : 99999;
182  $type = $config['type'] ?: 'range';
183  $validationRules[] = [
184  'type' => $type,
185  'minItems' => $minItems,
186  'maxItems' => $maxItems
187  ];
188  }
189  if (!empty($config['required'])) {
190  $validationRules[] = ['type' => 'required'];
191  }
192  return json_encode($validationRules);
193  }
194 }
‪TYPO3\CMS\Backend\Form\AbstractNode\$defaultFieldInformation
‪array $defaultFieldInformation
Definition: AbstractNode.php:48
‪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:116
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:90
‪TYPO3\CMS\Backend\Form\AbstractNode\$nodeFactory
‪NodeFactory $nodeFactory
Definition: AbstractNode.php:36
‪TYPO3\CMS\Backend\Form\AbstractNode\$defaultFieldControl
‪array $defaultFieldControl
Definition: AbstractNode.php:55
‪TYPO3\CMS\Backend\Form\AbstractNode\$defaultFieldWizard
‪array $defaultFieldWizard
Definition: AbstractNode.php:62
‪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:151
‪TYPO3\CMS\Backend\Form\AbstractNode\__construct
‪__construct(NodeFactory $nodeFactory, array $data)
Definition: AbstractNode.php:70
‪TYPO3\CMS\Backend\Form\AbstractNode\$data
‪array $data
Definition: AbstractNode.php:42
‪TYPO3\CMS\Backend\Form\NodeInterface
Definition: NodeInterface.php:22
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪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:46