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