[TASK] Use BE Routing / PSR-7 instead of BackendUtility::getModuleUrl
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FieldControl / LinkPopup.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
21 /**
22 * Renders the icon with link parameters to open the element browser.
23 * Used in InputLinkElement.
24 */
25 class LinkPopup extends AbstractNode
26 {
27 /**
28 * Link popup control
29 *
30 * @return array As defined by FieldControl class
31 */
32 public function render(): array
33 {
34 $options = $this->data['renderData']['fieldControlOptions'];
35
36 $title = $options['title'] ?? 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.link';
37
38 $parameterArray = $this->data['parameterArray'];
39 $itemName = $parameterArray['itemFormElName'];
40 $windowOpenParameters = $options['windowOpenParameters'] ?? 'height=800,width=1000,status=0,menubar=0,scrollbars=1';
41
42 $linkBrowserArguments = [];
43 if (isset($options['blindLinkOptions'])) {
44 $linkBrowserArguments['blindLinkOptions'] = $options['blindLinkOptions'];
45 }
46 if (isset($options['blindLinkFields'])) {
47 $linkBrowserArguments['blindLinkFields'] = $options['blindLinkFields'];
48 }
49 if (isset($options['allowedExtensions'])) {
50 $linkBrowserArguments['allowedExtensions'] = $options['allowedExtensions'];
51 }
52 $urlParameters = [
53 'P' => [
54 'params' => $linkBrowserArguments,
55 'table' => $this->data['tableName'],
56 'uid' => $this->data['databaseRow']['uid'],
57 'pid' => $this->data['databaseRow']['pid'],
58 'field' => $this->data['fieldName'],
59 'formName' => 'editform',
60 'itemName' => $itemName,
61 'hmac' => GeneralUtility::hmac('editform' . $itemName, 'wizard_js'),
62 'fieldChangeFunc' => $parameterArray['fieldChangeFunc'],
63 'fieldChangeFuncHash' => GeneralUtility::hmac(serialize($parameterArray['fieldChangeFunc'])),
64 ],
65 ];
66 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
67 $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
68 $url = (string)$uriBuilder->buildUriFromRoute('wizard_link', $urlParameters);
69 $onClick = [];
70 $onClick[] = 'this.blur();';
71 $onClick[] = 'vHWin=window.open(';
72 $onClick[] = GeneralUtility::quoteJSvalue($url);
73 $onClick[] = '+\'&P[currentValue]=\'+TBE_EDITOR.rawurlencode(';
74 $onClick[] = 'document.editform[' . GeneralUtility::quoteJSvalue($itemName) . '].value,300';
75 $onClick[] = ')';
76 $onClick[] = '+\'&P[currentSelectedValues]=\'+TBE_EDITOR.curSelected(';
77 $onClick[] = GeneralUtility::quoteJSvalue($itemName);
78 $onClick[] = '),';
79 $onClick[] = '\'\',';
80 $onClick[] = GeneralUtility::quoteJSvalue($windowOpenParameters);
81 $onClick[] = ');';
82 $onClick[] = 'vHWin.focus();';
83 $onClick[] = 'return false;';
84
85 return [
86 'iconIdentifier' => 'actions-wizard-link',
87 'title' => $title,
88 'linkAttributes' => [
89 'onClick' => implode('', $onClick),
90 ],
91 ];
92 }
93 }