‪TYPO3CMS  ‪main
TableList.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 
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Core\Imaging\IconSize;
27 
33 {
34  public function ‪__construct(
35  private readonly ‪IconFactory $iconFactory,
36  ) {}
37 
41  public function ‪render(): array
42  {
43  $languageService = $this->‪getLanguageService();
44  $result = $this->‪initializeResultArray();
45 
46  $parameterArray = $this->data['parameterArray'];
47  $config = $parameterArray['fieldConf']['config'];
48  $itemName = $parameterArray['itemFormElName'];
49 
50  if (empty($config['allowed']) || !is_string($config['allowed'])) {
51  // No handling if the field has no, or funny "allowed" settings.
52  return $result;
53  }
54 
55  $allowed = ‪GeneralUtility::trimExplode(',', $config['allowed'], true);
56  $allowedTablesHtml = [];
57  foreach ($allowed as $tableName) {
58  if ($tableName === '*') {
59  $label = $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.allTables');
60  $allowedTablesHtml[] = '<span>';
61  $allowedTablesHtml[] = htmlspecialchars($label);
62  $allowedTablesHtml[] = '</span>';
63  } else {
64  $label = $languageService->sL(‪$GLOBALS['TCA'][$tableName]['ctrl']['title'] ?? '');
65  $icon = $this->iconFactory->getIconForRecord($tableName, [], IconSize::SMALL)->render();
66  if ((bool)($config['fieldControl']['elementBrowser']['disabled'] ?? false)) {
67  $allowedTablesHtml[] = '<span class="tablelist-item-nolink">';
68  $allowedTablesHtml[] = $icon;
69  $allowedTablesHtml[] = htmlspecialchars($label);
70  $allowedTablesHtml[] = '</span>';
71  } else {
72  // Initialize attributes
73  $attributes = [
74  'class' => 'btn btn-default t3js-element-browser',
75  'data-mode' => 'db',
76  'data-params' => $itemName . '|||' . $tableName,
77  ];
78 
79  // Add the entry point - if found
80  $attributes = $this->‪addEntryPoint($tableName, $config, $attributes);
81 
82  $allowedTablesHtml[] = '<button ' . GeneralUtility::implodeAttributes($attributes, true) . '>';
83  $allowedTablesHtml[] = $icon;
84  $allowedTablesHtml[] = htmlspecialchars($label);
85  $allowedTablesHtml[] = '</button>';
86  }
87  }
88  }
89 
90  $html = [];
91  $html[] = '<div class="form-text">';
92  $html[] = implode(LF, $allowedTablesHtml);
93  $html[] = '</div>';
94 
95  $result['html'] = implode(LF, $html);
96  return $result;
97  }
98 
103  protected function ‪addEntryPoint(string $tableName, array $fieldConfig, array $attributes): array
104  {
105  if (!isset($fieldConfig['elementBrowserEntryPoints']) || !is_array($fieldConfig['elementBrowserEntryPoints'])) {
106  // Early return in case no entry points are defined
107  return $attributes;
108  }
109 
110  // Fetch the configured value (which might be a marker) - falls back to _default
111  $entryPoint = (string)($fieldConfig['elementBrowserEntryPoints'][$tableName] ?? $fieldConfig['elementBrowserEntryPoints']['_default'] ?? '');
112 
113  if ($entryPoint === '') {
114  // In case no entry point exists for the given table and also no default is defined, return
115  return $attributes;
116  }
117 
118  // Check and resolve possible marker
119  if (str_starts_with($entryPoint, '###') && str_ends_with($entryPoint, '###')) {
120  if ($entryPoint === '###CURRENT_PID###') {
121  // Use the current pid
122  $entryPoint = (string)$this->data['effectivePid'];
123  } elseif ($entryPoint === '###SITEROOT###' && ($this->data['site'] ?? null) instanceof ‪Site) {
124  // Use the root page id from the current site
125  $entryPoint = (string)$this->data['site']->getRootPageId();
126  } else {
127  // Check for special TSconfig marker
128  $TSconfig = BackendUtility::getTCEFORM_TSconfig($this->data['tableName'], ['pid' => $this->data['effectivePid']]);
129  $keyword = substr($entryPoint, 3, -3);
130  if (str_starts_with($keyword, 'PAGE_TSCONFIG_')) {
131  $entryPoint = (string)($TSconfig[$this->data['fieldName']][$keyword] ?? '');
132  } else {
133  $entryPoint = (string)($TSconfig['_' . $keyword] ?? '');
134  }
135  }
136  }
137 
138  // Add the entry point to the attribute - if resolved
139  if ($entryPoint !== '') {
140  $attributes['data-entry-point'] = $entryPoint;
141  }
142 
143  return $attributes;
144  }
145 
147  {
148  return ‪$GLOBALS['LANG'];
149  }
150 }
‪TYPO3\CMS\Backend\Form\FieldWizard\TableList\getLanguageService
‪getLanguageService()
Definition: TableList.php:146
‪TYPO3\CMS\Backend\Form\FieldWizard\TableList\addEntryPoint
‪addEntryPoint(string $tableName, array $fieldConfig, array $attributes)
Definition: TableList.php:103
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Backend\Form\FieldWizard\TableList\render
‪render()
Definition: TableList.php:41
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:42
‪TYPO3\CMS\Backend\Form\FieldWizard
Definition: DefaultLanguageDifferences.php:18
‪TYPO3\CMS\Backend\Form\FieldWizard\TableList
Definition: TableList.php:33
‪TYPO3\CMS\Backend\Form\FieldWizard\TableList\__construct
‪__construct(private readonly IconFactory $iconFactory,)
Definition: TableList.php:34
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode(string $delim, string $string, bool $removeEmptyValues=false, int $limit=0)
Definition: GeneralUtility.php:822
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪initializeResultArray()
Definition: AbstractNode.php:77