[!!!][FEATURE] FormEngine element level refactoring
[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 $languageService = $this->getLanguageService();
38
39 $table = $this->data['tableName'];
40 $row = $this->data['databaseRow'];
41 $fieldName = $this->data['fieldName'];
42 $flexFormFormPrefix = $this->data['flexFormFormPrefix'];
43 $flexFormContainerElementCollapsed = $this->data['flexFormContainerElementCollapsed'];
44 $flexFormDataStructureArray = $this->data['flexFormDataStructureArray'];
45 $parameterArray = $this->data['parameterArray'];
46
47 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
48 $toggleIcons = '<span class="t3js-flex-control-toggle-icon-open" style="' . ($flexFormContainerElementCollapsed ? 'display: none;' : '') . '">'
49 . $iconFactory->getIcon('actions-view-list-collapse', Icon::SIZE_SMALL)->render()
50 . '</span>';
51 $toggleIcons .= '<span class="t3js-flex-control-toggle-icon-close" style="' . ($flexFormContainerElementCollapsed ? '' : 'display: none;') . '">'
52 . $iconFactory->getIcon('actions-view-list-expand', Icon::SIZE_SMALL)->render()
53 . '</span>';
54
55 $flexFormContainerIdentifier = $this->data['flexFormContainerIdentifier'];
56 $actionFieldName = '_ACTION_FLEX_FORM'
57 . $parameterArray['itemFormElName']
58 . $this->data['flexFormFormPrefix']
59 . '[_ACTION]'
60 . '[' . $flexFormContainerIdentifier . ']';
61 $toggleFieldName = 'data[' . $table . '][' . $row['uid'] . '][' . $fieldName . ']'
62 . $flexFormFormPrefix
63 . '[' . $flexFormContainerIdentifier . ']'
64 . '[_TOGGLE]';
65
66 $moveAndDeleteContent = [];
67 $userHasAccessToDefaultLanguage = $this->getBackendUserAuthentication()->checkLanguageAccess(0);
68 if ($userHasAccessToDefaultLanguage) {
69 $moveAndDeleteContent[] = '<span class="btn btn-default t3js-sortable-handle"><span title="' . htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:sortable.dragmove')) . '">' . $iconFactory->getIcon('actions-move-move', Icon::SIZE_SMALL)->render() . '</span></span>';
70 $moveAndDeleteContent[] = '<span class="btn btn-default t3js-delete"><span title="' . htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:delete')) . '">' . $iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</span></span>';
71 }
72
73 $options = $this->data;
74 // Append container specific stuff to field prefix
75 $options['flexFormFormPrefix'] = $flexFormFormPrefix . '[' . $flexFormContainerIdentifier . '][' . $this->data['flexFormContainerName'] . '][el]';
76 $options['flexFormDataStructureArray'] = $flexFormDataStructureArray['el'];
77 $options['renderType'] = 'flexFormElementContainer';
78 $containerContentResult = $this->nodeFactory->create($options)->render();
79
80 $containerTitle = '';
81 if (!empty(trim($flexFormDataStructureArray['title']))) {
82 $containerTitle = $languageService->sL(trim($flexFormDataStructureArray['title']));
83 }
84
85 $html = [];
86 $html[] = '<div class="t3-form-field-container-flexsections t3-flex-section t3js-flex-section">';
87 $html[] = '<input class="t3-flex-control t3js-flex-control-action" type="hidden" name="' . htmlspecialchars($actionFieldName) . '" value="" />';
88 $html[] = '<div class="panel panel-default panel-condensed">';
89 $html[] = '<div class="panel-heading t3js-flex-section-header" data-toggle="formengine-flex">';
90 $html[] = '<div class="form-irre-header">';
91 $html[] = '<div class="form-irre-header-cell form-irre-header-icon">';
92 $html[] = $toggleIcons;
93 $html[] = '</div>';
94 $html[] = '<div class="form-irre-header-cell form-irre-header-body">';
95 $html[] = '<span class="t3js-record-title">' . htmlspecialchars($containerTitle) . '</span>';
96 $html[] = '</div>';
97 $html[] = '<div class="form-irre-header-cell form-irre-header-control">';
98 $html[] = '<div class="btn-group btn-group-sm">';
99 $html[] = implode(LF, $moveAndDeleteContent);
100 $html[] = '</div>';
101 $html[] = '</div>';
102 $html[] = '</div>';
103 $html[] = '</div>';
104 $html[] = '<div class="panel-collapse t3js-flex-section-content"' . ($flexFormContainerElementCollapsed ? ' style="display:none;"' : '') . '>';
105 $html[] = $containerContentResult['html'];
106 $html[] = '</div>';
107 $html[] = '<input';
108 $html[] = 'class="t3-flex-control t3js-flex-control-toggle"';
109 $html[] = 'type="hidden"';
110 $html[] = 'name="' . htmlspecialchars($toggleFieldName) . '"';
111 $html[] = 'value="' . ($flexFormContainerElementCollapsed ? '1' : '0') . '"';
112 $html[] = '/>';
113 $html[] = '</div>';
114 $html[] = '</div>';
115
116 $resultArray = $this->initializeResultArray();
117 $resultArray['html'] = implode(LF, $html);
118 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $containerContentResult, false);
119
120 return $resultArray;
121 }
122
123 /**
124 * @return BackendUserAuthentication
125 */
126 protected function getBackendUserAuthentication()
127 {
128 return $GLOBALS['BE_USER'];
129 }
130
131 /**
132 * @return LanguageService
133 */
134 protected function getLanguageService()
135 {
136 return $GLOBALS['LANG'];
137 }
138 }