‪TYPO3CMS  9.5
TableList.php
Go to the documentation of this file.
1 <?php
2 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 
23 
29 {
35  public function ‪render(): array
36  {
37  $languageService = $this->‪getLanguageService();
38  $result = $this->‪initializeResultArray();
39 
40  $parameterArray = $this->data['parameterArray'];
41  $config = $parameterArray['fieldConf']['config'];
42  $itemName = $parameterArray['itemFormElName'];
43 
44  if (!isset($config['allowed']) || !is_string($config['allowed']) || empty($config['allowed'])
45  || !isset($config['internal_type']) || $config['internal_type'] !== 'db'
46  ) {
47  // No handling if the field has no, or funny "allowed" setting, and if internal_type is not "db"
48  return $result;
49  }
50 
51  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
52  $allowed = GeneralUtility::trimExplode(',', $config['allowed'], true);
53  $allowedTablesHtml = [];
54  foreach ($allowed as $tableName) {
55  if ($tableName === '*') {
56  $label = $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.allTables');
57  $allowedTablesHtml[] = '<span>';
58  $allowedTablesHtml[] = htmlspecialchars($label);
59  $allowedTablesHtml[] = '</span>';
60  } else {
61  $label = $languageService->sL(‪$GLOBALS['TCA'][$tableName]['ctrl']['title']);
62  $icon = $iconFactory->getIconForRecord($tableName, [], ‪Icon::SIZE_SMALL)->render();
63  if ((bool)($config['fieldControl']['elementBrowser']['disabled'] ?? false)) {
64  $allowedTablesHtml[] = '<span class="tablelist-item-nolink">';
65  $allowedTablesHtml[] = $icon;
66  $allowedTablesHtml[] = htmlspecialchars($label);
67  $allowedTablesHtml[] = '</span>';
68  } else {
69  $onClick = [];
70  $onClick[] = 'setFormValueOpenBrowser(';
71  $onClick[] = '\'db\',';
72  $onClick[] = GeneralUtility::quoteJSvalue($itemName . '|||' . $tableName);
73  $onClick[] = ');';
74  $onClick[] = 'return false;';
75  $allowedTablesHtml[] = '<a href="#" onClick="' . htmlspecialchars(implode('', $onClick)) . '" class="btn btn-default">';
76  $allowedTablesHtml[] = $icon;
77  $allowedTablesHtml[] = htmlspecialchars($label);
78  $allowedTablesHtml[] = '</a>';
79  }
80  }
81  }
82 
83  $html = [];
84  $html[] = '<div class="help-block">';
85  $html[] = implode(LF, $allowedTablesHtml);
86  $html[] = '</div>';
87 
88  $result['html'] = implode(LF, $html);
89  return $result;
90  }
91 
95  protected function ‪getLanguageService()
96  {
97  return ‪$GLOBALS['LANG'];
98  }
99 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:88
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:31
‪TYPO3\CMS\Backend\Form\FieldWizard\TableList\render
‪array render()
Definition: TableList.php:35
‪TYPO3\CMS\Backend\Form\FieldWizard
Definition: DefaultLanguageDifferences.php:3
‪TYPO3\CMS\Backend\Form\FieldWizard\TableList
Definition: TableList.php:29
‪TYPO3\CMS\Backend\Form\FieldWizard\TableList\getLanguageService
‪LanguageService getLanguageService()
Definition: TableList.php:95
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45