1c4fe06b8b831abdee4c293afab13292c8b8a222
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FieldControl / EditPopup.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\Backend\Utility\BackendUtility;
20 use TYPO3\CMS\Core\Localization\LanguageService;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23 /**
24 * Renders the icon with link parameters to edit a selected element,
25 * typically used for single elements of type=group or type=select.
26 */
27 class EditPopup extends AbstractNode
28 {
29 /**
30 * Edit popup control
31 *
32 * @return array As defined by FieldControl class
33 */
34 public function render()
35 {
36 $languageService = $this->getLanguageService();
37 $options = $this->data['renderData']['fieldControlOptions'];
38
39 $title = $options['title'] ?? 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.edit';
40
41 $parameterArray = $this->data['parameterArray'];
42 $itemName = $parameterArray['itemFormElName'];
43 $windowOpenParameters = $options['windowOpenParameters'] ?? 'height=800,width=600,status=0,menubar=0,scrollbars=1';
44
45 $urlParameters = [
46 'P' => [
47 'table' => $this->data['tableName'],
48 'field' => $this->data['fieldName'],
49 'formName' => 'editform',
50 'hmac' => GeneralUtility::hmac('editform' . $itemName, 'wizard_js'),
51 'fieldChangeFunc' => $parameterArray['fieldChangeFunc'],
52 'fieldChangeFuncHash' => GeneralUtility::hmac(serialize($parameterArray['fieldChangeFunc'])),
53 ],
54 ];
55
56 $url = BackendUtility::getModuleUrl('wizard_edit', $urlParameters);
57 $onClick = [];
58 $onClick[] = 'this.blur();';
59 $onClick[] = 'if (!TBE_EDITOR.curSelected(' . GeneralUtility::quoteJSvalue($itemName) . ')) {';
60 $onClick[] = 'top.TYPO3.Modal.confirm(';
61 $onClick[] = '"' . $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.header') . '",';
62 $onClick[] = '"' . $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:mess.noSelItemForEdit') . '",';
63 $onClick[] = 'top.TYPO3.Severity.notice, [{text: TYPO3.lang[\'button.ok\'] || \'OK\', btnClass: \'btn-notice\', name: \'ok\'}]';
64 $onClick[] = ')';
65 $onClick[] = '.on("button.clicked", function(e) {';
66 $onClick[] = 'if (e.target.name == "ok") { top.TYPO3.Modal.dismiss(); }}';
67 $onClick[] = ');';
68 $onClick[] = 'return false;';
69 $onClick[] = '}';
70 $onClick[] = 'vHWin=window.open(';
71 $onClick[] = GeneralUtility::quoteJSvalue($url);
72 $onClick[] = '+\'&P[currentValue]=\'+TBE_EDITOR.rawurlencode(';
73 $onClick[] = 'document.editform[' . GeneralUtility::quoteJSvalue($itemName) . '].value,300';
74 $onClick[] = ')';
75 $onClick[] = '+\'&P[currentSelectedValues]=\'+TBE_EDITOR.curSelected(';
76 $onClick[] = GeneralUtility::quoteJSvalue($itemName);
77 $onClick[] = '),';
78 $onClick[] = '\'\',';
79 $onClick[] = GeneralUtility::quoteJSvalue($windowOpenParameters);
80 $onClick[] = ');';
81 $onClick[] = 'vHWin.focus();';
82 $onClick[] = 'return false;';
83
84 return [
85 'iconIdentifier' => 'actions-open',
86 'title' => $title,
87 'linkAttributes' => [
88 'onClick' => implode('', $onClick),
89 ],
90 ];
91 }
92
93 /**
94 * Returns an instance of LanguageService
95 *
96 * @return LanguageService
97 */
98 protected function getLanguageService()
99 {
100 return $GLOBALS['LANG'];
101 }
102 }