TYPO3 CMS  TYPO3_8-7
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 
28 class TableList extends AbstractNode
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 ($allowed === '*') {
56  $label = $languageService->sL('LLL:EXT:lang/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  $onClick = [];
63  $onClick[] = 'setFormValueOpenBrowser(';
64  $onClick[] = '\'db\',';
65  $onClick[] = GeneralUtility::quoteJSvalue($itemName . '|||' . $tableName);
66  $onClick[] = ');';
67  $onClick[] = 'return false;';
68  $allowedTablesHtml[] = '<a href="#" onClick="' . htmlspecialchars(implode('', $onClick)) . '" class="btn btn-default">';
69  $allowedTablesHtml[] = $iconFactory->getIconForRecord($tableName, [], Icon::SIZE_SMALL)->render();
70  $allowedTablesHtml[] = htmlspecialchars($label);
71  $allowedTablesHtml[] = '</a>';
72  }
73  }
74 
75  $html= [];
76  $html[] = '<div class="help-block">';
77  $html[] = implode(LF, $allowedTablesHtml);
78  $html[] = '</div>';
79 
80  $result['html'] = implode(LF, $html);
81  return $result;
82  }
83 
87  protected function getLanguageService()
88  {
89  return $GLOBALS['LANG'];
90  }
91 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']