TYPO3  7.6
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 
27 
40 {
47  protected static $allowOverrideMatrix = array(
48  'input' => array('size', 'max', 'readOnly'),
49  'text' => array('cols', 'rows', 'wrap', 'readOnly'),
50  'check' => array('cols', 'showIfRTE', 'readOnly'),
51  'select' => array('size', 'autoSizeMax', 'maxitems', 'minitems', 'readOnly', 'treeConfig'),
52  'group' => array('size', 'autoSizeMax', 'max_size', 'show_thumbs', 'maxitems', 'minitems', 'disable_controls', 'readOnly'),
53  'inline' => array('appearance', 'behaviour', 'foreign_label', 'foreign_selector', 'foreign_unique', 'maxitems', 'minitems', 'size', 'autoSizeMax', 'symmetric_label', 'readOnly'),
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 (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  static $cache;
101  if (is_null($cache)) {
102  $cache = array();
103  }
104  $cacheIdentifier = $table . ':' . $row['uid'];
105  if (!isset($cache[$cacheIdentifier])) {
106  $cache[$cacheIdentifier] = BackendUtility::getTCEFORM_TSconfig($table, $row);
107  }
108  if ($field) {
109  return $cache[$cacheIdentifier][$field];
110  }
111  return $cache[$cacheIdentifier];
112  }
113 
123  public static function getIconHtml($icon, $alt = '', $title = '')
124  {
125  $icon = (string)$icon;
126  $iconFile = '';
127  $iconInfo = false;
128 
129  if (StringUtility::beginsWith($icon, 'EXT:')) {
130  $absoluteFilePath = GeneralUtility::getFileAbsFileName($icon);
131  if (!empty($absoluteFilePath)) {
132  $iconFile = '../' . PathUtility::stripPathSitePrefix($absoluteFilePath);
133  $iconInfo = (StringUtility::endsWith($absoluteFilePath, '.svg'))
134  ? true
135  : getimagesize($absoluteFilePath);
136  }
137  } elseif (StringUtility::beginsWith($icon, '../')) {
138  // @TODO: this is special modList, files from folders and selicon
139  $iconFile = GeneralUtility::resolveBackPath($icon);
140  if (is_file(PATH_site . GeneralUtility::resolveBackPath(substr($icon, 3)))) {
141  $iconInfo = (StringUtility::endsWith($icon, '.svg'))
142  ? true
143  : getimagesize((PATH_site . GeneralUtility::resolveBackPath(substr($icon, 3))));
144  }
145  }
146 
147  if ($iconInfo !== false && is_file(GeneralUtility::resolveBackPath(PATH_typo3 . $iconFile))) {
148  return '<img'
149  . ' src="' . htmlspecialchars($iconFile) . '"'
150  . ' alt="' . htmlspecialchars($alt) . '" '
151  . ($title ? 'title="' . htmlspecialchars($title) . '"' : '')
152  . ' />';
153  }
154 
155  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
156  return '<span alt="' . htmlspecialchars($alt) . '" title="' . htmlspecialchars($title) . '">'
157  . $iconFactory->getIcon($icon, Icon::SIZE_SMALL)->render()
158  . '</span>';
159  }
160 
169  public static function updateInlineView(&$uc, $tce)
170  {
171  $backendUser = static::getBackendUserAuthentication();
172  if (isset($uc['inlineView']) && is_array($uc['inlineView'])) {
173  $inlineView = (array)unserialize($backendUser->uc['inlineView']);
174  foreach ($uc['inlineView'] as $topTable => $topRecords) {
175  foreach ($topRecords as $topUid => $childElements) {
176  foreach ($childElements as $childTable => $childRecords) {
177  $uids = array_keys($tce->substNEWwithIDs_table, $childTable);
178  if (!empty($uids)) {
179  $newExpandedChildren = array();
180  foreach ($childRecords as $childUid => $state) {
181  if ($state && in_array($childUid, $uids)) {
182  $newChildUid = $tce->substNEWwithIDs[$childUid];
183  $newExpandedChildren[] = $newChildUid;
184  }
185  }
186  // Add new expanded child records to UC (if any):
187  if (!empty($newExpandedChildren)) {
188  $inlineViewCurrent = &$inlineView[$topTable][$topUid][$childTable];
189  if (is_array($inlineViewCurrent)) {
190  $inlineViewCurrent = array_unique(array_merge($inlineViewCurrent, $newExpandedChildren));
191  } else {
192  $inlineViewCurrent = $newExpandedChildren;
193  }
194  }
195  }
196  }
197  }
198  }
199  $backendUser->uc['inlineView'] = serialize($inlineView);
200  $backendUser->writeUC();
201  }
202  }
203 
217  public static function databaseRowCompatibility(array $row)
218  {
219  $newRow = [];
220  foreach ($row as $fieldName => $fieldValue) {
221  if (!is_array($fieldValue)) {
222  $newRow[$fieldName] = $fieldValue;
223  } else {
224  $newElementValue = [];
225  foreach ($fieldValue as $itemNumber => $itemValue) {
226  if (is_array($itemValue) && array_key_exists(1, $itemValue)) {
227  $newElementValue[] = $itemValue[1];
228  } else {
229  $newElementValue[] = $itemValue;
230  }
231  }
232  $newRow[$fieldName] = implode(',', $newElementValue);
233  }
234  }
235  return $newRow;
236  }
237 
241  protected static function getLanguageService()
242  {
243  return $GLOBALS['LANG'];
244  }
245 
249  protected static function getDatabaseConnection()
250  {
251  return $GLOBALS['TYPO3_DB'];
252  }
253 
257  protected static function getBackendUserAuthentication()
258  {
259  return $GLOBALS['BE_USER'];
260  }
261 }