[TASK] Use BE Routing / PSR-7 instead of BackendUtility::getModuleUrl
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FieldControl / TableWizard.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\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Core\Utility\MathUtility;
21
22 /**
23 * Renders the icon with link parameters to the table wizard,
24 * typically used for type=text with renderType=textTable.
25 */
26 class TableWizard 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 $itemName = $parameterArray['itemFormElName'];
38 $row = $this->data['databaseRow'];
39
40 if (!MathUtility::canBeInterpretedAsInteger($row['uid'])) {
41 return [];
42 }
43
44 // Handle options and fallback
45 $title = $options['title'] ?? 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.tableWizard';
46 $xmlOutput = isset($options['xmlOutput']) ? (int)$options['xmlOutput'] : 0;
47 $numNewRows = isset($options['numNewRows']) ? (int)$options['numNewRows'] : 5;
48
49 $prefixOfFormElName = 'data[' . $this->data['tableName'] . '][' . $this->data['databaseRow']['uid'] . '][' . $this->data['fieldName'] . ']';
50 $flexFormPath = '';
51 if (GeneralUtility::isFirstPartOfStr($itemName, $prefixOfFormElName)) {
52 $flexFormPath = str_replace('][', '/', substr($itemName, strlen($prefixOfFormElName) + 1, -1));
53 }
54
55 $urlParameters = [
56 'P' => [
57 'params' => [
58 'xmlOutput' => $xmlOutput,
59 'numNewRows' => $numNewRows,
60 ],
61 'table' => $this->data['tableName'],
62 'field' => $this->data['fieldName'],
63 'uid' => $this->data['databaseRow']['uid'],
64 'flexFormPath' => $flexFormPath,
65 'returnUrl' => $this->data['returnUrl'],
66 ],
67 ];
68
69 $onClick = [];
70 $onClick[] = 'this.blur();';
71 $onClick[] = 'return !TBE_EDITOR.isFormChanged();';
72 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
73 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
74 return [
75 'iconIdentifier' => 'content-table',
76 'title' => $title,
77 'linkAttributes' => [
78 'onClick' => implode('', $onClick),
79 'href' => (string)$uriBuilder->buildUriFromRoute('wizard_table', $urlParameters),
80 ],
81 ];
82 }
83 }