Passed
Push — master ( ae79e2...ceb903 )
by
unknown
38:15 queued 17:24
created

EditPopup::getLanguageService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
18
namespace TYPO3\CMS\Backend\Form\FieldControl;
19
20
use TYPO3\CMS\Backend\Form\AbstractNode;
21
use TYPO3\CMS\Backend\Routing\UriBuilder;
22
use TYPO3\CMS\Core\Utility\GeneralUtility;
23
use TYPO3\CMS\Core\Utility\StringUtility;
24
25
/**
26
 * Renders the icon with link parameters to edit a selected element,
27
 * typically used for single elements of type=group or type=select.
28
 */
29
class EditPopup extends AbstractNode
30
{
31
    /**
32
     * Edit popup control
33
     *
34
     * @return array As defined by FieldControl class
35
     */
36
    public function render()
37
    {
38
        $options = $this->data['renderData']['fieldControlOptions'];
39
40
        $title = $options['title'] ?? 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.edit';
41
42
        $parameterArray = $this->data['parameterArray'];
43
        $itemName = $parameterArray['itemFormElName'];
44
        $windowOpenParameters = $options['windowOpenParameters'] ?? 'height=800,width=600,status=0,menubar=0,scrollbars=1';
45
46
        $flexFormDataStructureIdentifier = $this->data['flexFormDataStructureIdentifier'] ?? '';
47
        $flexFormDataStructurePath = '';
48
        if (!empty($flexFormDataStructureIdentifier)) {
49
            if (empty($this->data['flexFormContainerName'])) {
50
                // simple flex form element
51
                $flexFormDataStructurePath = 'sheets/'
52
                    . $this->data['flexFormSheetName']
53
                    . '/ROOT/el/'
54
                    . $this->data['flexFormFieldName']
55
                    . '/TCEforms/config';
56
            } else {
57
                // flex form section container element
58
                $flexFormDataStructurePath = 'sheets/'
59
                    . $this->data['flexFormSheetName']
60
                    . '/ROOT/el/'
61
                    . $this->data['flexFormFieldName']
62
                    . '/el/'
63
                    . $this->data['flexFormContainerName']
64
                    . '/el/'
65
                    . $this->data['flexFormContainerFieldName']
66
                    . '/TCEforms/config';
67
            }
68
        }
69
70
        $urlParameters = [
71
            'P' => [
72
                'table' => $this->data['tableName'],
73
                'field' => $this->data['fieldName'],
74
                'formName' => 'editform',
75
                'flexFormDataStructureIdentifier' => $flexFormDataStructureIdentifier,
76
                'flexFormDataStructurePath' => $flexFormDataStructurePath,
77
                'hmac' => GeneralUtility::hmac('editform' . $itemName, 'wizard_js'),
78
                'fieldChangeFunc' => $parameterArray['fieldChangeFunc'],
79
                'fieldChangeFuncHash' => GeneralUtility::hmac(serialize($parameterArray['fieldChangeFunc']), 'backend-link-browser'),
80
            ],
81
        ];
82
        $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
83
        $url = (string)$uriBuilder->buildUriFromRoute('wizard_edit', $urlParameters);
84
85
        $id = StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
86
87
        return [
88
            'iconIdentifier' => 'actions-open',
89
            'title' => $title,
90
            'linkAttributes' => [
91
                'id' => htmlspecialchars($id),
92
                'href' => $url,
93
                'data-element' => $itemName,
94
                'data-window-parameters' => $windowOpenParameters,
95
            ],
96
            'requireJsModules' => [
97
                ['TYPO3/CMS/Backend/FormEngine/FieldControl/EditPopup' => 'function(FieldControl) {new FieldControl(' . GeneralUtility::quoteJSvalue('#' . $id) . ');}'],
98
            ],
99
        ];
100
    }
101
}
102