1<?php
2
3/*
4 * This file is part of the TYPO3 CMS project.
5 *
6 * It is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License, either version 2
8 * of the License, or any later version.
9 *
10 * For the full copyright and license information, please read the
11 * LICENSE.txt file that was distributed with this source code.
12 *
13 * The TYPO3 project - inspiring people to share!
14 */
15
16namespace TYPO3\CMS\Backend\Form\Container;
17
18use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
19use TYPO3\CMS\Core\Imaging\Icon;
20use TYPO3\CMS\Core\Imaging\IconFactory;
21use TYPO3\CMS\Core\Localization\LanguageService;
22use TYPO3\CMS\Core\Utility\GeneralUtility;
23
24/**
25 * Flex form container implementation
26 * This one is called by FlexFormSectionContainer and renders HTML for a single container.
27 * For processing of single elements FlexFormElementContainer is called
28 */
29class FlexFormContainerContainer extends AbstractContainer
30{
31    /**
32     * Entry method
33     *
34     * @return array As defined in initializeResultArray() of AbstractNode
35     */
36    public function render()
37    {
38        $languageService = $this->getLanguageService();
39
40        $table = $this->data['tableName'];
41        $row = $this->data['databaseRow'];
42        $fieldName = $this->data['fieldName'];
43        $flexFormFormPrefix = $this->data['flexFormFormPrefix'];
44        $flexFormContainerElementCollapsed = $this->data['flexFormContainerElementCollapsed'];
45        $flexFormDataStructureArray = $this->data['flexFormDataStructureArray'];
46        $parameterArray = $this->data['parameterArray'];
47
48        $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
49        $toggleIcons = '<span class="t3js-flex-control-toggle-icon-open" style="' . ($flexFormContainerElementCollapsed ? 'display: none;' : '') . '">'
50            . $iconFactory->getIcon('actions-view-list-collapse', Icon::SIZE_SMALL)->render()
51            . '</span>';
52        $toggleIcons .= '<span class="t3js-flex-control-toggle-icon-close" style="' . ($flexFormContainerElementCollapsed ? '' : 'display: none;') . '">'
53            . $iconFactory->getIcon('actions-view-list-expand', Icon::SIZE_SMALL)->render()
54            . '</span>';
55
56        $flexFormContainerIdentifier = $this->data['flexFormContainerIdentifier'];
57        $actionFieldName = '_ACTION_FLEX_FORM'
58            . $parameterArray['itemFormElName']
59            . $this->data['flexFormFormPrefix']
60            . '[_ACTION]'
61            . '[' . $flexFormContainerIdentifier . ']';
62        $toggleFieldName = 'data[' . $table . '][' . $row['uid'] . '][' . $fieldName . ']'
63            . $flexFormFormPrefix
64            . '[' . $flexFormContainerIdentifier . ']'
65            . '[_TOGGLE]';
66
67        $moveAndDeleteContent = [];
68        $userHasAccessToDefaultLanguage = $this->getBackendUserAuthentication()->checkLanguageAccess(0);
69        if ($userHasAccessToDefaultLanguage) {
70            $moveAndDeleteContent[] = '<span class="btn btn-default t3js-sortable-handle"><span title="' . htmlspecialchars($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:sortable.dragmove')) . '">' . $iconFactory->getIcon('actions-move-move', Icon::SIZE_SMALL)->render() . '</span></span>';
71            $moveAndDeleteContent[] = '<span class="btn btn-default t3js-delete"><span title="' . htmlspecialchars($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:delete')) . '">' . $iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</span></span>';
72        }
73
74        $options = $this->data;
75        // Append container specific stuff to field prefix
76        $options['flexFormFormPrefix'] = $flexFormFormPrefix . '[' . $flexFormContainerIdentifier . '][' . $this->data['flexFormContainerName'] . '][el]';
77        $options['flexFormDataStructureArray'] = $flexFormDataStructureArray['el'];
78        $options['renderType'] = 'flexFormElementContainer';
79        $containerContentResult = $this->nodeFactory->create($options)->render();
80
81        $containerTitle = '';
82        if (!empty(trim($flexFormDataStructureArray['title']))) {
83            $containerTitle = $languageService->sL(trim($flexFormDataStructureArray['title']));
84        }
85
86        $resultArray = $this->initializeResultArray();
87
88        $html = [];
89        $html[] = '<div class="t3-form-field-container-flexsections t3-flex-section t3js-flex-section">';
90        $html[] =    '<input class="t3-flex-control t3js-flex-control-action" type="hidden" name="' . htmlspecialchars($actionFieldName) . '" value="" />';
91        $html[] =    '<div class="panel panel-default panel-condensed">';
92        $html[] =        '<div class="panel-heading t3js-flex-section-header" data-toggle="formengine-flex">';
93        $html[] =            '<div class="form-irre-header">';
94        $html[] =                '<div class="form-irre-header-cell form-irre-header-icon">';
95        $html[] =                    $toggleIcons;
96        $html[] =                '</div>';
97        $html[] =                '<div class="form-irre-header-cell form-irre-header-body">';
98        $html[] =                    '<span class="t3js-record-title">' . htmlspecialchars($containerTitle) . '</span>';
99        $html[] =                '</div>';
100        $html[] =                '<div class="form-irre-header-cell form-irre-header-control">';
101        $html[] =                    '<div class="btn-group btn-group-sm">';
102        $html[] =                        implode(LF, $moveAndDeleteContent);
103        $html[] =                    '</div>';
104        $html[] =                '</div>';
105        $html[] =            '</div>';
106        $html[] =        '</div>';
107        $html[] =        '<div class="panel-collapse t3js-flex-section-content"' . ($flexFormContainerElementCollapsed ? ' style="display:none;"' : '') . '>';
108        $html[] =            $containerContentResult['html'];
109        $html[] =        '</div>';
110        $html[] =        '<input';
111        $html[] =            'class="t3-flex-control t3js-flex-control-toggle"';
112        $html[] =            'type="hidden"';
113        $html[] =            'name="' . htmlspecialchars($toggleFieldName) . '"';
114        $html[] =            'value="' . ($flexFormContainerElementCollapsed ? '1' : '0') . '"';
115        $html[] =        '/>';
116        $html[] =    '</div>';
117        $html[] = '</div>';
118
119        $resultArray['html'] = implode(LF, $html);
120        $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $containerContentResult, false);
121
122        return $resultArray;
123    }
124
125    /**
126     * @return BackendUserAuthentication
127     */
128    protected function getBackendUserAuthentication()
129    {
130        return $GLOBALS['BE_USER'];
131    }
132
133    /**
134     * @return LanguageService
135     */
136    protected function getLanguageService()
137    {
138        return $GLOBALS['LANG'];
139    }
140}
141