e7f560dc7677e4ec9ba4b6c6d18be3c1173ae551
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FieldControl / ListModule.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Backend\Form\FieldControl;
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
18 use TYPO3\CMS\Backend\Form\AbstractNode;
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * Renders the icon with link parameters to jump to the list module
24 * "single table" view, showing only one configurable table.
25 */
26 class ListModule extends AbstractNode
27 {
28 /**
29 * Add button control
30 *
31 * @return array As defined by FieldControl class
32 */
33 public function render()
34 {
35 $options = $this->data['renderData']['fieldControlOptions'];
36 $parameterArray = $this->data['parameterArray'];
37
38 // Handle options and fallback
39 $title = $options['title'] ?? 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.list';
40
41 $table = '';
42 if (isset($options['table'])) {
43 // Table given in options - use it
44 $table = $options['table'];
45 } elseif ($parameterArray['fieldConf']['config']['type'] === 'group'
46 && isset($parameterArray['fieldConf']['config']['internal_type'])
47 && $parameterArray['fieldConf']['config']['internal_type'] === 'db'
48 && !empty($parameterArray['fieldConf']['config']['allowed'])
49 ) {
50 // Use first table from allowed list if specific table is not set in options
51 $allowedTables = GeneralUtility::trimExplode(',', $parameterArray['fieldConf']['config']['allowed'], true);
52 $table = array_pop($allowedTables);
53 } elseif ($parameterArray['fieldConf']['config']['type'] === 'select'
54 && !empty($parameterArray['fieldConf']['config']['foreign_table'])
55 ) {
56 // Use foreign_table if given for type=select
57 $table = $parameterArray['fieldConf']['config']['foreign_table'];
58 }
59 if (empty($table)) {
60 // Still no table - this element can not handle the list control.
61 return [];
62 }
63
64 // Target pid of new records is current pid by default
65 $pid = $this->data['effectivePid'];
66 if (isset($options['pid'])) {
67 // pid configured in options - use it
68 $pid = $options['pid'];
69 } elseif (isset($GLOBALS['TCA'][$table]['ctrl']['rootLevel']) && (int)$GLOBALS['TCA'][$table]['ctrl'] === 1) {
70 // Target table can only exist on root level - set 0 as pid
71 $pid = 0;
72 }
73
74 $urlParameters = [
75 'P' => [
76 'params' => [
77 'table' => $table,
78 'pid' => $pid,
79 ],
80 'table' => $this->data['tableName'],
81 'uid' => $this->data['databaseRow']['uid'],
82 'returnUrl' => $this->data['returnUrl'],
83 ],
84 ];
85
86 $onClick = [];
87 $onClick[] = 'this.blur();';
88 $onClick[] = 'return !TBE_EDITOR.isFormChanged();';
89
90 return [
91 'iconIdentifier' => 'actions-system-list-open',
92 'title' => $title,
93 'linkAttributes' => [
94 'onClick' => implode('', $onClick),
95 'href' => BackendUtility::getModuleUrl('wizard_list', $urlParameters),
96 ],
97 ];
98 }
99 }