‪TYPO3CMS  10.4
ListModule.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 
24 
30 {
36  public function ‪render()
37  {
38  $options = $this->data['renderData']['fieldControlOptions'];
39  $parameterArray = $this->data['parameterArray'];
40 
41  // Handle options and fallback
42  $title = $options['title'] ?? 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.list';
43 
44  $table = '';
45  if (isset($options['table'])) {
46  // Table given in options - use it
47  $table = $options['table'];
48  } elseif ($parameterArray['fieldConf']['config']['type'] === 'group'
49  && isset($parameterArray['fieldConf']['config']['internal_type'])
50  && $parameterArray['fieldConf']['config']['internal_type'] === 'db'
51  && !empty($parameterArray['fieldConf']['config']['allowed'])
52  ) {
53  // Use first table from allowed list if specific table is not set in options
54  $allowedTables = ‪GeneralUtility::trimExplode(',', $parameterArray['fieldConf']['config']['allowed'], true);
55  $table = array_pop($allowedTables);
56  } elseif ($parameterArray['fieldConf']['config']['type'] === 'select'
57  && !empty($parameterArray['fieldConf']['config']['foreign_table'])
58  ) {
59  // Use foreign_table if given for type=select
60  $table = $parameterArray['fieldConf']['config']['foreign_table'];
61  }
62  if (empty($table)) {
63  // Still no table - this element can not handle the list control.
64  return [];
65  }
66 
67  // Target pid of new records is current pid by default
68  $pid = $this->data['effectivePid'];
69  if (isset($options['pid'])) {
70  // pid configured in options - use it
71  $pid = $options['pid'];
72  } elseif (isset(‪$GLOBALS['TCA'][$table]['ctrl']['rootLevel']) && (int)‪$GLOBALS['TCA'][$table]['ctrl'] === 1) {
73  // Target table can only exist on root level - set 0 as pid
74  $pid = 0;
75  }
76 
77  $urlParameters = [
78  'P' => [
79  'params' => [
80  'table' => $table,
81  'pid' => $pid,
82  ],
83  'table' => $this->data['tableName'],
84  'field' => $this->data['fieldName'],
85  'uid' => $this->data['databaseRow']['uid'],
86  'returnUrl' => $this->data['returnUrl'],
87  ],
88  ];
89 
90  $id = ‪StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
91 
93  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
94 
95  return [
96  'iconIdentifier' => 'actions-system-list-open',
97  'title' => $title,
98  'linkAttributes' => [
99  'id' => htmlspecialchars($id),
100  'href' => (string)$uriBuilder->buildUriFromRoute('wizard_list', $urlParameters),
101  ],
102  'requireJsModules' => [
103  ['TYPO3/CMS/Backend/FormEngine/FieldControl/ListModule' => 'function(FieldControl) {new FieldControl(' . GeneralUtility::quoteJSvalue('#' . $id) . ');}'],
104  ],
105  ];
106  }
107 }
‪TYPO3\CMS\Backend\Form\FieldControl
Definition: AddRecord.php:18
‪TYPO3\CMS\Backend\Form\FieldControl\ListModule\render
‪array render()
Definition: ListModule.php:36
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Backend\Form\FieldControl\ListModule
Definition: ListModule.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:92
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22