‪TYPO3CMS  11.5
FlexFormSectionContainer.php
Go to the documentation of this file.
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 
17 
24 
35 {
41  public function ‪render()
42  {
43  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
44  $languageService = $this->‪getLanguageService();
45 
46  $flexFormDataStructureIdentifier = $this->data['flexFormDataStructureIdentifier'];
47  $flexFormDataStructureArray = $this->data['flexFormDataStructureArray'];
48  $flexFormRowData = $this->data['flexFormRowData'];
49  $flexFormFieldName = $this->data['flexFormFieldName'];
50  $flexFormSheetName = $this->data['flexFormSheetName'];
51 
52  $userHasAccessToDefaultLanguage = $this->‪getBackendUserAuthentication()->‪checkLanguageAccess(0);
53 
54  $resultArray = $this->‪initializeResultArray();
55 
56  // Render each existing container
57  foreach ($flexFormDataStructureArray['children'] as $flexFormContainerIdentifier => $containerDataStructure) {
58  $existingContainerData = $flexFormRowData[$flexFormContainerIdentifier];
59  // @todo: This relies on the fact that "_TOGGLE" is *below* the real data in the saved xml structure
60  $existingSectionContainerDataStructureType = key($existingContainerData);
61  $existingContainerData = $existingContainerData[$existingSectionContainerDataStructureType];
62  $options = ‪$this->data;
63  $options['flexFormRowData'] = $existingContainerData['el'];
64  $options['flexFormDataStructureArray'] = $containerDataStructure;
65  $options['flexFormFormPrefix'] = $this->data['flexFormFormPrefix'] . '[' . $flexFormFieldName . '][el]';
66  $options['flexFormContainerName'] = $existingSectionContainerDataStructureType;
67  $options['flexFormContainerIdentifier'] = $flexFormContainerIdentifier;
68  $options['flexFormContainerElementCollapsed'] = (bool)($flexFormRowData[$flexFormContainerIdentifier]['_TOGGLE'] ?? false);
69  $options['renderType'] = 'flexFormContainerContainer';
70  $flexFormContainerContainerResult = $this->nodeFactory->create($options)->render();
71  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $flexFormContainerContainerResult);
72  }
73 
74  $containerId = sprintf('flexform-section-container-%s-%s', $this->data['fieldName'], $flexFormFieldName);
75  $sectionContainerId = sprintf('flexform-section-%s-%s', $this->data['fieldName'], $flexFormFieldName);
76  $hashedSectionContainerId = 'section-' . md5($sectionContainerId);
77 
78  // "New container" handling: Creates buttons for each possible container with all relevant information for the ajax call.
79  $containerTemplatesHtml = [];
80  foreach ($flexFormDataStructureArray['el'] as $flexFormContainerName => $flexFormFieldDefinition) {
81  $containerTitle = '';
82  if (!empty(trim($flexFormFieldDefinition['title']))) {
83  $containerTitle = $languageService->sL(trim($flexFormFieldDefinition['title']));
84  }
85  $containerTemplateHtml = [];
86  $containerTemplateHtml[] = '<a';
87  $containerTemplateHtml[] = 'href="#"';
88  $containerTemplateHtml[] = 'class="btn btn-default t3js-flex-container-add"';
89  $containerTemplateHtml[] = 'data-vanillauid="' . (int)$this->data['vanillaUid'] . '"';
90  // no int cast for databaseRow uid, this can be "NEW1234..."
91  $containerTemplateHtml[] = 'data-databaserowuid="' . htmlspecialchars($this->data['databaseRow']['uid']) . '"';
92  $containerTemplateHtml[] = 'data-command="' . htmlspecialchars($this->data['command']) . '"';
93  $containerTemplateHtml[] = 'data-tablename="' . htmlspecialchars($this->data['tableName']) . '"';
94  $containerTemplateHtml[] = 'data-fieldname="' . htmlspecialchars($this->data['fieldName']) . '"';
95  $containerTemplateHtml[] = 'data-recordtypevalue="' . $this->data['recordTypeValue'] . '"';
96  $containerTemplateHtml[] = 'data-datastructureidentifier="' . htmlspecialchars($flexFormDataStructureIdentifier) . '"';
97  $containerTemplateHtml[] = 'data-flexformsheetname="' . htmlspecialchars($flexFormSheetName) . '"';
98  $containerTemplateHtml[] = 'data-flexformfieldname="' . htmlspecialchars($flexFormFieldName) . '"';
99  $containerTemplateHtml[] = 'data-flexformcontainername="' . htmlspecialchars($flexFormContainerName) . '"';
100  $containerTemplateHtml[] = 'data-target="#' . htmlspecialchars($hashedSectionContainerId) . '"';
101  $containerTemplateHtml[] = '>';
102  $containerTemplateHtml[] = $iconFactory->getIcon('actions-document-new', ‪Icon::SIZE_SMALL)->render();
103  $containerTemplateHtml[] = htmlspecialchars(GeneralUtility::fixed_lgd_cs($containerTitle, 30));
104  $containerTemplateHtml[] = '</a>';
105  $containerTemplatesHtml[] = implode(LF, $containerTemplateHtml);
106  }
107  // Create new elements links
108  $createElementsHtml = [];
109  if ($userHasAccessToDefaultLanguage) {
110  $createElementsHtml[] = '<div class="t3-form-field-add-flexsection">';
111  $createElementsHtml[] = '<div class="btn-group">';
112  $createElementsHtml[] = implode('', $containerTemplatesHtml);
113  $createElementsHtml[] = '</div>';
114  $createElementsHtml[] = '</div>';
115  }
116 
117  $sectionTitle = '';
118  if (!empty(trim($flexFormDataStructureArray['title'] ?? ''))) {
119  $sectionTitle = $languageService->sL(trim($flexFormDataStructureArray['title']));
120  }
121 
122  // Wrap child stuff
123  $toggleAll = htmlspecialchars($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.toggleall'));
124  $html = [];
125  $html[] = '<div class="panel panel-tab">';
126  $html[] = '<div class="panel-body">';
127  $html[] = '<div class="t3-form-field-container t3-form-flex" id="' . htmlspecialchars($containerId) . '" data-section="#' . htmlspecialchars($hashedSectionContainerId) . '">';
128  $html[] = '<div class="t3-form-field-label-flexsection">';
129  $html[] = '<h4>';
130  $html[] = htmlspecialchars($sectionTitle);
131  $html[] = '</h4>';
132  $html[] = '</div>';
133  $html[] = '<div class="form-group">';
134  $html[] = '<button class="btn btn-default t3-form-flexsection-toggle" type="button" title="' . $toggleAll . '" data-expand-all="false">';
135  $html[] = $iconFactory->getIcon('actions-move-right', ‪Icon::SIZE_SMALL)->render() . $toggleAll;
136  $html[] = '</button>';
137  $html[] = '</div>';
138  $html[] = '<div';
139  $html[] = 'id="' . htmlspecialchars($hashedSectionContainerId) . '"';
140  $html[] = 'class="panel-group panel-hover t3-form-field-container-flexsection t3-flex-container"';
141  $html[] = 'data-t3-flex-allow-restructure="' . ($userHasAccessToDefaultLanguage ? '1' : '0') . '"';
142  $html[] = '>';
143  $html[] = $resultArray['html'];
144  $html[] = '</div>';
145  $html[] = implode(LF, $createElementsHtml);
146  $html[] = '</div>';
147  $html[] = '</div>';
148  $html[] = '</div>';
149 
150  $resultArray['html'] = implode(LF, $html);
151  $resultArray['requireJsModules'][] = ‪JavaScriptModuleInstruction::forRequireJS(
152  'TYPO3/CMS/Backend/FormEngine/Container/FlexFormSectionContainer'
153  )->instance($containerId);
154 
155  return $resultArray;
156  }
157 
161  protected function ‪getBackendUserAuthentication()
162  {
163  return ‪$GLOBALS['BE_USER'];
164  }
165 
169  protected function ‪getLanguageService()
170  {
171  return ‪$GLOBALS['LANG'];
172  }
173 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Backend\Form\Container\FlexFormSectionContainer\render
‪array render()
Definition: FlexFormSectionContainer.php:41
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:120
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:91
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Backend\Form\Container
Definition: AbstractContainer.php:16
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction
Definition: JavaScriptModuleInstruction.php:23
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction\forRequireJS
‪static self forRequireJS(string $name, string $exportName=null)
Definition: JavaScriptModuleInstruction.php:49
‪TYPO3\CMS\Backend\Form\Container\FlexFormSectionContainer\getBackendUserAuthentication
‪BackendUserAuthentication getBackendUserAuthentication()
Definition: FlexFormSectionContainer.php:161
‪TYPO3\CMS\Backend\Form\AbstractNode\$data
‪array $data
Definition: AbstractNode.php:43
‪TYPO3\CMS\Backend\Form\Container\AbstractContainer
Definition: AbstractContainer.php:28
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\checkLanguageAccess
‪bool checkLanguageAccess($langValue)
Definition: BackendUserAuthentication.php:670
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Form\Container\FlexFormSectionContainer\getLanguageService
‪LanguageService getLanguageService()
Definition: FlexFormSectionContainer.php:169
‪TYPO3\CMS\Backend\Form\Container\FlexFormSectionContainer
Definition: FlexFormSectionContainer.php:35