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