‪TYPO3CMS  9.5
ListModule.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 
21 
27 {
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:core/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  $id = ‪StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
87 
89  $uriBuilder = GeneralUtility::makeInstance(\‪TYPO3\CMS\Backend\Routing\UriBuilder::class);
90 
91  return [
92  'iconIdentifier' => 'actions-system-list-open',
93  'title' => $title,
94  'linkAttributes' => [
95  'id' => htmlspecialchars($id),
96  'href' => (string)$uriBuilder->buildUriFromRoute('wizard_list', $urlParameters),
97  ],
98  'requireJsModules' => [
99  ['TYPO3/CMS/Backend/FormEngine/FieldControl/ListModule' => 'function(FieldControl) {new FieldControl(' . GeneralUtility::quoteJSvalue('#' . $id) . ');}'],
100  ],
101  ];
102  }
103 }
‪TYPO3\CMS\Backend\Form\FieldControl
Definition: AddRecord.php:3
‪TYPO3\CMS\Backend\Form\FieldControl\ListModule\render
‪array render()
Definition: ListModule.php:33
‪TYPO3
‪TYPO3\CMS\Backend\Form\FieldControl\ListModule
Definition: ListModule.php:27
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:91
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:21