‪TYPO3CMS  10.4
FormEngineUtility.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
26 
39 {
46  protected static ‪$allowOverrideMatrix = [
47  'input' => ['size', 'max', 'readOnly'],
48  'text' => ['cols', 'rows', 'wrap', 'max', 'readOnly'],
49  'check' => ['cols', 'readOnly'],
50  'select' => ['size', 'autoSizeMax', 'maxitems', 'minitems', 'readOnly', 'treeConfig'],
51  'group' => ['size', 'autoSizeMax', 'max_size', 'maxitems', 'minitems', 'readOnly'],
52  'inline' => ['appearance', 'behaviour', 'foreign_label', 'foreign_selector', 'foreign_unique', 'maxitems', 'minitems', 'size', 'autoSizeMax', 'symmetric_label', 'readOnly'],
53  'imageManipulation' => ['ratios', 'cropVariants']
54  ];
55 
67  public static function ‪overrideFieldConf($fieldConfig, $TSconfig)
68  {
69  if (is_array($TSconfig)) {
70  $TSconfig = GeneralUtility::removeDotsFromTS($TSconfig);
71  $type = $fieldConfig['type'] ?? '';
72  if (isset($TSconfig['config']) && is_array($TSconfig['config']) && is_array(static::$allowOverrideMatrix[$type])) {
73  // Check if the keys in TSconfig['config'] are allowed to override TCA field config:
74  foreach ($TSconfig['config'] as $key => $_) {
75  if (!in_array($key, static::$allowOverrideMatrix[$type], true)) {
76  unset($TSconfig['config'][$key]);
77  }
78  }
79  // Override $GLOBALS['TCA'] field config by remaining TSconfig['config']:
80  if (!empty($TSconfig['config'])) {
81  ‪ArrayUtility::mergeRecursiveWithOverrule($fieldConfig, $TSconfig['config']);
82  }
83  }
84  }
85  return $fieldConfig;
86  }
87 
98  public static function ‪getTSconfigForTableRow($table, $row, $field = '')
99  {
100  $runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
101  $cache = $runtimeCache->get('formEngineUtilityTsConfigForTableRow') ?: [];
102  $cacheIdentifier = $table . ':' . $row['uid'];
103  if (!isset($cache[$cacheIdentifier])) {
104  $cache[$cacheIdentifier] = ‪BackendUtility::getTCEFORM_TSconfig($table, $row);
105  $runtimeCache->set('formEngineUtilityTsConfigForTableRow', $cache);
106  }
107  if ($field && isset($cache[$cacheIdentifier][$field])) {
108  return $cache[$cacheIdentifier][$field];
109  }
110  return $cache[$cacheIdentifier];
111  }
112 
122  public static function ‪getIconHtml($icon, $alt = '', $title = '')
123  {
124  $icon = (string)$icon;
125  $absoluteFilePath = GeneralUtility::getFileAbsFileName($icon);
126  if (!empty($absoluteFilePath) && is_file($absoluteFilePath)) {
127  return '<img'
128  . ' loading="lazy" '
129  . ' src="' . htmlspecialchars(‪PathUtility::getAbsoluteWebPath($absoluteFilePath)) . '"'
130  . ' alt="' . htmlspecialchars($alt) . '" '
131  . ($title ? 'title="' . htmlspecialchars($title) . '"' : '')
132  . ' />';
133  }
134 
135  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
136  return '<span title="' . htmlspecialchars($title) . '">'
137  . $iconFactory->getIcon($icon, ‪Icon::SIZE_SMALL)->render()
138  . '</span>';
139  }
140 
148  public static function ‪updateInlineView(&$uc, $tce)
149  {
150  $backendUser = static::getBackendUserAuthentication();
151  if (isset($uc['inlineView']) && is_array($uc['inlineView'])) {
152  $inlineView = (array)json_decode($backendUser->uc['inlineView'], true);
153  foreach ($uc['inlineView'] as $topTable => $topRecords) {
154  foreach ($topRecords as $topUid => $childElements) {
155  foreach ($childElements as $childTable => $childRecords) {
156  $uids = array_keys($tce->substNEWwithIDs_table, $childTable);
157  if (!empty($uids)) {
158  $newExpandedChildren = [];
159  foreach ($childRecords as $childUid => $state) {
160  if ($state && in_array($childUid, $uids)) {
161  $newChildUid = $tce->substNEWwithIDs[$childUid];
162  $newExpandedChildren[] = $newChildUid;
163  }
164  }
165  // Add new expanded child records to UC (if any):
166  if (!empty($newExpandedChildren)) {
167  $inlineViewCurrent = &$inlineView[$topTable][$topUid][$childTable];
168  if (is_array($inlineViewCurrent)) {
169  $inlineViewCurrent = array_unique(array_merge($inlineViewCurrent, $newExpandedChildren));
170  } else {
171  $inlineViewCurrent = $newExpandedChildren;
172  }
173  }
174  }
175  }
176  }
177  }
178  $backendUser->uc['inlineView'] = json_encode($inlineView);
179  $backendUser->writeUC();
180  }
181  }
182 
196  public static function ‪databaseRowCompatibility(array $row)
197  {
198  $newRow = [];
199  foreach ($row as $fieldName => $fieldValue) {
200  if (!is_array($fieldValue)) {
201  $newRow[$fieldName] = $fieldValue;
202  } else {
203  $newElementValue = [];
204  foreach ($fieldValue as $itemNumber => $itemValue) {
205  if (is_array($itemValue) && array_key_exists(1, $itemValue)) {
206  $newElementValue[] = $itemValue[1];
207  } else {
208  $newElementValue[] = $itemValue;
209  }
210  }
211  $newRow[$fieldName] = implode(',', $newElementValue);
212  }
213  }
214  return $newRow;
215  }
216 
220  protected static function ‪getBackendUserAuthentication()
221  {
222  return ‪$GLOBALS['BE_USER'];
223  }
224 }
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\getBackendUserAuthentication
‪static BackendUserAuthentication getBackendUserAuthentication()
Definition: FormEngineUtility.php:219
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\getTSconfigForTableRow
‪static mixed getTSconfigForTableRow($table, $row, $field='')
Definition: FormEngineUtility.php:97
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:24
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\databaseRowCompatibility
‪static array databaseRowCompatibility(array $row)
Definition: FormEngineUtility.php:195
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪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\Utility\FormEngineUtility
Definition: FormEngineUtility.php:39
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\updateInlineView
‪static updateInlineView(&$uc, $tce)
Definition: FormEngineUtility.php:147
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\getIconHtml
‪static string getIconHtml($icon, $alt='', $title='')
Definition: FormEngineUtility.php:121
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\Backend\Form\Utility
Definition: FormEngineUtility.php:16
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\$allowOverrideMatrix
‪static array $allowOverrideMatrix
Definition: FormEngineUtility.php:45
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Utility\BackendUtility\getTCEFORM_TSconfig
‪static array getTCEFORM_TSconfig($table, $row)
Definition: BackendUtility.php:3096
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:43
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\overrideFieldConf
‪static array overrideFieldConf($fieldConfig, $TSconfig)
Definition: FormEngineUtility.php:66