‪TYPO3CMS  ‪main
FormEngineUtility.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 TYPO3\CMS\Backend\Utility\BackendUtility;
24 use TYPO3\CMS\Core\Imaging\IconSize;
28 
41 {
48  protected static ‪$allowOverrideMatrix = [
49  'input' => ['size', 'max', 'readOnly'],
50  'number' => ['size', 'readOnly'],
51  'email' => ['size', 'readOnly'],
52  'link' => ['size', 'readOnly'],
53  'password' => ['size', 'readOnly'],
54  'datetime' => ['size', 'readOnly'],
55  'color' => ['size', 'readOnly'],
56  'uuid' => ['size', 'enableCopyToClipboard'],
57  'text' => ['cols', 'rows', 'wrap', 'max', 'readOnly'],
58  'json' => ['cols', 'rows', 'readOnly'],
59  'check' => ['cols', 'readOnly'],
60  'select' => ['size', 'autoSizeMax', 'maxitems', 'minitems', 'readOnly', 'treeConfig', 'fileFolderConfig'],
61  'category' => ['size', 'maxitems', 'minitems', 'readOnly', 'treeConfig'],
62  'group' => ['size', 'autoSizeMax', 'maxitems', 'minitems', 'readOnly', 'elementBrowserEntryPoints'],
63  'folder' => ['size', 'autoSizeMax', 'maxitems', 'minitems', 'readOnly', 'elementBrowserEntryPoints'],
64  'inline' => ['appearance', 'behaviour', 'foreign_label', 'foreign_selector', 'foreign_unique', 'maxitems', 'minitems', 'size', 'autoSizeMax', 'symmetric_label', 'readOnly'],
65  'file' => ['appearance', 'behaviour', 'maxitems', 'minitems', 'readOnly'],
66  'imageManipulation' => ['ratios', 'cropVariants'],
67  ];
68 
80  public static function ‪overrideFieldConf($fieldConfig, $TSconfig)
81  {
82  if (is_array($TSconfig)) {
83  $TSconfig = GeneralUtility::removeDotsFromTS($TSconfig);
84  $type = $fieldConfig['type'] ?? '';
85  if (isset($TSconfig['config']) && is_array($TSconfig['config']) && is_array(static::$allowOverrideMatrix[$type])) {
86  // Check if the keys in TSconfig['config'] are allowed to override TCA field config:
87  foreach ($TSconfig['config'] as $key => $_) {
88  if (!in_array($key, static::$allowOverrideMatrix[$type], true)) {
89  unset($TSconfig['config'][$key]);
90  }
91  }
92  // Override $GLOBALS['TCA'] field config by remaining TSconfig['config']:
93  if (!empty($TSconfig['config'])) {
94  ArrayUtility::mergeRecursiveWithOverrule($fieldConfig, $TSconfig['config']);
95  }
96  }
97  }
98  return $fieldConfig;
99  }
100 
111  public static function ‪getTSconfigForTableRow($table, $row, $field = '')
112  {
113  $runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
114  $cache = $runtimeCache->get('formEngineUtilityTsConfigForTableRow') ?: [];
115  $cacheIdentifier = $table . ':' . $row['uid'];
116  if (!isset($cache[$cacheIdentifier])) {
117  $cache[$cacheIdentifier] = BackendUtility::getTCEFORM_TSconfig($table, $row);
118  $runtimeCache->set('formEngineUtilityTsConfigForTableRow', $cache);
119  }
120  if ($field && isset($cache[$cacheIdentifier][$field])) {
121  return $cache[$cacheIdentifier][$field];
122  }
123  return $cache[$cacheIdentifier];
124  }
125 
135  public static function ‪getIconHtml($icon, $alt = '', $title = '')
136  {
137  $icon = (string)$icon;
138  if (‪PathUtility::isAbsolutePath($icon)) {
139  $absoluteFilePath = $icon;
140  } else {
141  $absoluteFilePath = GeneralUtility::getFileAbsFileName($icon);
142  }
143  if (!empty($absoluteFilePath) && (is_file($absoluteFilePath)) || is_file(‪Environment::getPublicPath() . $absoluteFilePath)) {
144  return '<img'
145  . ' loading="lazy" '
146  . ' src="' . htmlspecialchars(‪PathUtility::getAbsoluteWebPath($absoluteFilePath)) . '"'
147  . ' alt="' . htmlspecialchars($alt) . '" '
148  . ($title ? 'title="' . htmlspecialchars($title) . '"' : '')
149  . ' />';
150  }
151 
152  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
153  return $iconFactory
154  ->getIcon($icon, IconSize::SMALL)
155  ->setTitle($title)
156  ->render();
157  }
158 }
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\getTSconfigForTableRow
‪static mixed getTSconfigForTableRow($table, $row, $field='')
Definition: FormEngineUtility.php:110
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Core\Utility\PathUtility\isAbsolutePath
‪static isAbsolutePath(string $path)
Definition: PathUtility.php:286
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static getPublicPath()
Definition: Environment.php:187
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility
Definition: FormEngineUtility.php:41
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath(string $targetPath, bool $prefixWithSitePath=true)
Definition: PathUtility.php:52
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\getIconHtml
‪static string getIconHtml($icon, $alt='', $title='')
Definition: FormEngineUtility.php:134
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Backend\Form\Utility
Definition: FormEngineUtility.php:18
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\$allowOverrideMatrix
‪static array $allowOverrideMatrix
Definition: FormEngineUtility.php:47
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:26
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Form\Utility\FormEngineUtility\overrideFieldConf
‪static array overrideFieldConf($fieldConfig, $TSconfig)
Definition: FormEngineUtility.php:79