TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
FormEngineUtility.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Form\Utility;
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', 'readOnly'],
48  'check' => ['cols', 'readOnly'],
49  'select' => ['size', 'autoSizeMax', 'maxitems', 'minitems', 'readOnly', 'treeConfig'],
50  'group' => ['size', 'autoSizeMax', 'max_size', 'show_thumbs', 'maxitems', 'minitems', 'disable_controls', 'readOnly'],
51  'inline' => ['appearance', 'behaviour', 'foreign_label', 'foreign_selector', 'foreign_unique', 'maxitems', 'minitems', 'size', 'autoSizeMax', 'symmetric_label', 'readOnly'],
52  'imageManipulation' => ['ratios']
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 (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  static $cache;
100  if (is_null($cache)) {
101  $cache = [];
102  }
103  $cacheIdentifier = $table . ':' . $row['uid'];
104  if (!isset($cache[$cacheIdentifier])) {
105  $cache[$cacheIdentifier] = BackendUtility::getTCEFORM_TSconfig($table, $row);
106  }
107  if ($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  $iconInfo = StringUtility::endsWith($absoluteFilePath, '.svg')
128  ? true
129  : getimagesize($absoluteFilePath);
130 
131  if ($iconInfo !== false) {
132  return '<img'
133  . ' src="' . htmlspecialchars(PathUtility::getAbsoluteWebPath($absoluteFilePath)) . '"'
134  . ' alt="' . htmlspecialchars($alt) . '" '
135  . ($title ? 'title="' . htmlspecialchars($title) . '"' : '')
136  . ' />';
137  }
138  }
139 
140  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
141  return '<span alt="' . htmlspecialchars($alt) . '" title="' . htmlspecialchars($title) . '">'
142  . $iconFactory->getIcon($icon, Icon::SIZE_SMALL)->render()
143  . '</span>';
144  }
145 
154  public static function updateInlineView(&$uc, $tce)
155  {
156  $backendUser = static::getBackendUserAuthentication();
157  if (isset($uc['inlineView']) && is_array($uc['inlineView'])) {
158  $inlineView = (array)unserialize($backendUser->uc['inlineView']);
159  foreach ($uc['inlineView'] as $topTable => $topRecords) {
160  foreach ($topRecords as $topUid => $childElements) {
161  foreach ($childElements as $childTable => $childRecords) {
162  $uids = array_keys($tce->substNEWwithIDs_table, $childTable);
163  if (!empty($uids)) {
164  $newExpandedChildren = [];
165  foreach ($childRecords as $childUid => $state) {
166  if ($state && in_array($childUid, $uids)) {
167  $newChildUid = $tce->substNEWwithIDs[$childUid];
168  $newExpandedChildren[] = $newChildUid;
169  }
170  }
171  // Add new expanded child records to UC (if any):
172  if (!empty($newExpandedChildren)) {
173  $inlineViewCurrent = &$inlineView[$topTable][$topUid][$childTable];
174  if (is_array($inlineViewCurrent)) {
175  $inlineViewCurrent = array_unique(array_merge($inlineViewCurrent, $newExpandedChildren));
176  } else {
177  $inlineViewCurrent = $newExpandedChildren;
178  }
179  }
180  }
181  }
182  }
183  }
184  $backendUser->uc['inlineView'] = serialize($inlineView);
185  $backendUser->writeUC();
186  }
187  }
188 
202  public static function databaseRowCompatibility(array $row)
203  {
204  $newRow = [];
205  foreach ($row as $fieldName => $fieldValue) {
206  if (!is_array($fieldValue)) {
207  $newRow[$fieldName] = $fieldValue;
208  } else {
209  $newElementValue = [];
210  foreach ($fieldValue as $itemNumber => $itemValue) {
211  if (is_array($itemValue) && array_key_exists(1, $itemValue)) {
212  $newElementValue[] = $itemValue[1];
213  } else {
214  $newElementValue[] = $itemValue;
215  }
216  }
217  $newRow[$fieldName] = implode(',', $newElementValue);
218  }
219  }
220  return $newRow;
221  }
222 
226  protected static function getBackendUserAuthentication()
227  {
228  return $GLOBALS['BE_USER'];
229  }
230 }
static getIconHtml($icon, $alt= '', $title= '')
static endsWith($haystack, $needle)
static getTSconfigForTableRow($table, $row, $field= '')
static static overrideFieldConf($fieldConfig, $TSconfig)
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
static getFileAbsFileName($filename, $_=null, $_2=null)
static getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:40