TYPO3 CMS  TYPO3_7-6
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 
27 
40 {
47  protected static $allowOverrideMatrix = [
48  'input' => ['size', 'max', 'readOnly'],
49  'text' => ['cols', 'rows', 'wrap', 'readOnly'],
50  'check' => ['cols', 'showIfRTE', 'readOnly'],
51  'select' => ['size', 'autoSizeMax', 'maxitems', 'minitems', 'readOnly', 'treeConfig'],
52  'group' => ['size', 'autoSizeMax', 'max_size', 'show_thumbs', 'maxitems', 'minitems', 'disable_controls', 'readOnly'],
53  'inline' => ['appearance', 'behaviour', 'foreign_label', 'foreign_selector', 'foreign_unique', 'maxitems', 'minitems', 'size', 'autoSizeMax', 'symmetric_label', 'readOnly'],
54  'imageManipulation' => ['ratios']
55  ];
56 
68  public static function overrideFieldConf($fieldConfig, $TSconfig)
69  {
70  if (is_array($TSconfig)) {
71  $TSconfig = GeneralUtility::removeDotsFromTS($TSconfig);
72  $type = $fieldConfig['type'];
73  if (is_array($TSconfig['config']) && is_array(static::$allowOverrideMatrix[$type])) {
74  // Check if the keys in TSconfig['config'] are allowed to override TCA field config:
75  foreach ($TSconfig['config'] as $key => $_) {
76  if (!in_array($key, static::$allowOverrideMatrix[$type], true)) {
77  unset($TSconfig['config'][$key]);
78  }
79  }
80  // Override $GLOBALS['TCA'] field config by remaining TSconfig['config']:
81  if (!empty($TSconfig['config'])) {
82  ArrayUtility::mergeRecursiveWithOverrule($fieldConfig, $TSconfig['config']);
83  }
84  }
85  }
86  return $fieldConfig;
87  }
88 
99  public static function getTSconfigForTableRow($table, $row, $field = '')
100  {
101  static $cache;
102  if (is_null($cache)) {
103  $cache = [];
104  }
105  $cacheIdentifier = $table . ':' . $row['uid'];
106  if (!isset($cache[$cacheIdentifier])) {
107  $cache[$cacheIdentifier] = BackendUtility::getTCEFORM_TSconfig($table, $row);
108  }
109  if ($field) {
110  return $cache[$cacheIdentifier][$field];
111  }
112  return $cache[$cacheIdentifier];
113  }
114 
124  public static function getIconHtml($icon, $alt = '', $title = '')
125  {
126  $icon = (string)$icon;
127  $iconFile = '';
128  $iconInfo = false;
129 
130  if (StringUtility::beginsWith($icon, 'EXT:')) {
131  $absoluteFilePath = GeneralUtility::getFileAbsFileName($icon);
132  if (!empty($absoluteFilePath) && is_file($absoluteFilePath)) {
133  $iconFile = '../' . PathUtility::stripPathSitePrefix($absoluteFilePath);
134  $iconInfo = (StringUtility::endsWith($absoluteFilePath, '.svg'))
135  ? true
136  : getimagesize($absoluteFilePath);
137  }
138  } elseif (StringUtility::beginsWith($icon, '../')) {
139  // @TODO: this is special modList, files from folders and selicon
140  $iconFile = GeneralUtility::resolveBackPath($icon);
141  if (is_file(PATH_site . GeneralUtility::resolveBackPath(substr($icon, 3)))) {
142  $iconInfo = (StringUtility::endsWith($icon, '.svg'))
143  ? true
144  : getimagesize((PATH_site . GeneralUtility::resolveBackPath(substr($icon, 3))));
145  }
146  }
147 
148  if ($iconInfo !== false && is_file(GeneralUtility::resolveBackPath(PATH_typo3 . $iconFile))) {
149  return '<img'
150  . ' src="' . htmlspecialchars($iconFile) . '"'
151  . ' alt="' . htmlspecialchars($alt) . '" '
152  . ($title ? 'title="' . htmlspecialchars($title) . '"' : '')
153  . ' />';
154  }
155 
156  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
157  return '<span alt="' . htmlspecialchars($alt) . '" title="' . htmlspecialchars($title) . '">'
158  . $iconFactory->getIcon($icon, Icon::SIZE_SMALL)->render()
159  . '</span>';
160  }
161 
170  public static function updateInlineView(&$uc, $tce)
171  {
172  $backendUser = static::getBackendUserAuthentication();
173  if (isset($uc['inlineView']) && is_array($uc['inlineView'])) {
174  $inlineView = (array)unserialize($backendUser->uc['inlineView']);
175  foreach ($uc['inlineView'] as $topTable => $topRecords) {
176  foreach ($topRecords as $topUid => $childElements) {
177  foreach ($childElements as $childTable => $childRecords) {
178  $uids = array_keys($tce->substNEWwithIDs_table, $childTable);
179  if (!empty($uids)) {
180  $newExpandedChildren = [];
181  foreach ($childRecords as $childUid => $state) {
182  if ($state && in_array($childUid, $uids)) {
183  $newChildUid = $tce->substNEWwithIDs[$childUid];
184  $newExpandedChildren[] = $newChildUid;
185  }
186  }
187  // Add new expanded child records to UC (if any):
188  if (!empty($newExpandedChildren)) {
189  $inlineViewCurrent = &$inlineView[$topTable][$topUid][$childTable];
190  if (is_array($inlineViewCurrent)) {
191  $inlineViewCurrent = array_unique(array_merge($inlineViewCurrent, $newExpandedChildren));
192  } else {
193  $inlineViewCurrent = $newExpandedChildren;
194  }
195  }
196  }
197  }
198  }
199  }
200  $backendUser->uc['inlineView'] = serialize($inlineView);
201  $backendUser->writeUC();
202  }
203  }
204 
218  public static function databaseRowCompatibility(array $row)
219  {
220  $newRow = [];
221  foreach ($row as $fieldName => $fieldValue) {
222  if (!is_array($fieldValue)) {
223  $newRow[$fieldName] = $fieldValue;
224  } else {
225  $newElementValue = [];
226  foreach ($fieldValue as $itemNumber => $itemValue) {
227  if (is_array($itemValue) && array_key_exists(1, $itemValue)) {
228  $newElementValue[] = $itemValue[1];
229  } else {
230  $newElementValue[] = $itemValue;
231  }
232  }
233  $newRow[$fieldName] = implode(',', $newElementValue);
234  }
235  }
236  return $newRow;
237  }
238 
242  protected static function getLanguageService()
243  {
244  return $GLOBALS['LANG'];
245  }
246 
250  protected static function getDatabaseConnection()
251  {
252  return $GLOBALS['TYPO3_DB'];
253  }
254 
258  protected static function getBackendUserAuthentication()
259  {
260  return $GLOBALS['BE_USER'];
261  }
262 }
static getTSconfigForTableRow($table, $row, $field='')
static getIconHtml($icon, $alt='', $title='')
static static overrideFieldConf($fieldConfig, $TSconfig)
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
static getFileAbsFileName($filename, $onlyRelative=true, $relToTYPO3_mainDir=false)
static beginsWith($haystack, $needle)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static endsWith($haystack, $needle)