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