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