[TASK] Call explicit render() on icon objects
[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 $table = $this->data['tableName'];
37 $row = $this->data['databaseRow'];
38 $fieldName = $this->data['fieldName'];
39 $flexFormFormPrefix = $this->data['flexFormFormPrefix'];
40 $flexFormContainerElementCollapsed = $this->data['flexFormContainerElementCollapsed'];
41 $flexFormContainerTitle = $this->data['flexFormContainerTitle'];
42 $flexFormFieldIdentifierPrefix = $this->data['flexFormFieldIdentifierPrefix'];
43 $parameterArray = $this->data['parameterArray'];
44
45 // Every container adds its own part to the id prefix
46 $flexFormFieldIdentifierPrefix = $flexFormFieldIdentifierPrefix . '-' . GeneralUtility::shortMd5(uniqid('id', TRUE));
47
48 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
49 $toggleIcons = '<span class="t3-flex-control-toggle-icon-open" style="' . ($flexFormContainerElementCollapsed ? 'display: none;' : '') . '">'
50 . $iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render()
51 . '</span>';
52 $toggleIcons .= '<span class="t3-flex-control-toggle-icon-close" style="' . ($flexFormContainerElementCollapsed ? '' : 'display: none;') . '">'
53 . $iconFactory->getIcon('actions-move-right', Icon::SIZE_SMALL)->render()
54 . '</span>';
55
56 $flexFormContainerCounter = $this->data['flexFormContainerCounter'];
57 $actionFieldName = '_ACTION_FLEX_FORM'
58 . $parameterArray['itemFormElName']
59 . $this->data['flexFormFormPrefix']
60 . '[_ACTION]'
61 . '[' . $flexFormContainerCounter . ']';
62 $toggleFieldName = 'data[' . $table . '][' . $row['uid'] . '][' . $fieldName . ']'
63 . $flexFormFormPrefix
64 . '[' . $flexFormContainerCounter . ']'
65 . '[_TOGGLE]';
66
67 $moveAndDeleteContent = array();
68 $userHasAccessToDefaultLanguage = $this->getBackendUserAuthentication()->checkLanguageAccess(0);
69 if ($userHasAccessToDefaultLanguage) {
70 $moveAndDeleteContent[] = '<div class="pull-right">';
71 $moveAndDeleteContent[] = '<span title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:sortable.dragmove', TRUE) . '" class="t3-js-sortable-handle">' . $iconFactory->getIcon('actions-move-move', Icon::SIZE_SMALL)->render() . '</span>';
72 $moveAndDeleteContent[] = '<span title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:delete', TRUE) . '" class="t3-js-delete">' . $iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</span>';
73 $moveAndDeleteContent[] = '</div>';
74 }
75
76 $options = $this->data;
77 $options['flexFormFieldIdentifierPrefix'] = $flexFormFieldIdentifierPrefix;
78 // Append container specific stuff to field prefix
79 $options['flexFormFormPrefix'] = $flexFormFormPrefix . '[' . $flexFormContainerCounter . '][' . $this->data['flexFormContainerName'] . '][el]';
80 $options['renderType'] = 'flexFormElementContainer';
81 $containerContentResult = $this->nodeFactory->create($options)->render();
82
83 $html = array();
84 $html[] = '<div id="' . $flexFormFieldIdentifierPrefix . '" class="t3-form-field-container-flexsections t3-flex-section">';
85 $html[] = '<input class="t3-flex-control t3-flex-control-action" type="hidden" name="' . htmlspecialchars($actionFieldName) . '" value="" />';
86 $html[] = '<div class="t3-form-field-header-flexsection t3-flex-section-header">';
87 $html[] = '<div class="pull-left">';
88 $html[] = '<a href="#" class="t3-flex-control-toggle-button">' . $toggleIcons . '</a>';
89 $html[] = '<span class="t3-record-title">' . $flexFormContainerTitle . '</span>';
90 $html[] = '</div>';
91 $html[] = implode(LF, $moveAndDeleteContent);
92 $html[] = '</div>';
93 $html[] = '<div class="t3-form-field-record-flexsection t3-flex-section-content"' . ($flexFormContainerElementCollapsed ? ' style="display:none;"' : '') . '>';
94 $html[] = $containerContentResult['html'];
95 $html[] = '</div>';
96 $html[] = '<input';
97 $html[] = 'class="t3-flex-control t3-flex-control-toggle"';
98 $html[] = 'id="' . $flexFormFieldIdentifierPrefix . '-toggleClosed"';
99 $html[] = 'type="hidden"';
100 $html[] = 'name="' . htmlspecialchars($toggleFieldName) . '"';
101 $html[] = 'value="' . ($flexFormContainerElementCollapsed ? '1' : '0') . '"';
102 $html[] = '/>';
103 $html[] = '</div>';
104
105 $containerContentResult['html'] = '';
106 $resultArray = $this->initializeResultArray();
107 $resultArray['html'] = implode(LF, $html);
108 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $containerContentResult);
109
110 return $resultArray;
111 }
112
113 /**
114 * @return BackendUserAuthentication
115 */
116 protected function getBackendUserAuthentication() {
117 return $GLOBALS['BE_USER'];
118 }
119
120 /**
121 * @return LanguageService
122 */
123 protected function getLanguageService() {
124 return $GLOBALS['LANG'];
125 }
126
127 }