‪TYPO3CMS  ‪main
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 
19 use TYPO3\CMS\Core\Imaging\IconSize;
23 
34 {
35  public function ‪__construct(
36  private readonly ‪IconFactory $iconFactory,
37  ) {}
38 
44  public function ‪render(): array
45  {
46  $languageService = $this->‪getLanguageService();
47 
48  $flexFormDataStructureIdentifier = $this->data['flexFormDataStructureIdentifier'];
49  $flexFormDataStructureArray = $this->data['flexFormDataStructureArray'];
50  $flexFormRowData = $this->data['flexFormRowData'];
51  $flexFormFieldName = $this->data['flexFormFieldName'];
52  $flexFormSheetName = $this->data['flexFormSheetName'];
53 
54  $userHasAccessToDefaultLanguage = $this->‪getBackendUserAuthentication()->checkLanguageAccess(0);
55 
56  $resultArray = $this->‪initializeResultArray();
57 
58  // Render each existing container
59  foreach ($flexFormDataStructureArray['children'] as $flexFormContainerIdentifier => $containerDataStructure) {
60  $existingContainerData = $flexFormRowData[$flexFormContainerIdentifier];
61  $existingSectionContainerDataStructureType = key($existingContainerData);
62  $existingContainerData = $existingContainerData[$existingSectionContainerDataStructureType];
63  $options = ‪$this->data;
64  $options['flexFormRowData'] = $existingContainerData['el'];
65  $options['flexFormDataStructureArray'] = $containerDataStructure;
66  $options['flexFormFormPrefix'] = $this->data['flexFormFormPrefix'] . '[' . $flexFormFieldName . '][el]';
67  $options['flexFormContainerName'] = $existingSectionContainerDataStructureType;
68  $options['flexFormContainerIdentifier'] = $flexFormContainerIdentifier;
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[] = $this->iconFactory->getIcon('actions-document-new', IconSize::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[] = $this->iconFactory->getIcon('actions-move-right', IconSize::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['javaScriptModules'][] = ‪JavaScriptModuleInstruction::create(
152  '@typo3/backend/form-engine/container/flex-form-section-container.js'
153  )->instance($containerId);
154 
155  return $resultArray;
156  }
157 
159  {
160  return ‪$GLOBALS['LANG'];
161  }
162 }
‪TYPO3\CMS\Backend\Form\Container\FlexFormSectionContainer\render
‪array render()
Definition: FlexFormSectionContainer.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility\fixed_lgd_cs
‪static string fixed_lgd_cs(string $string, int $chars, string $appendString='...')
Definition: GeneralUtility.php:92
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:104
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction\create
‪static create(string $name, string $exportName=null)
Definition: JavaScriptModuleInstruction.php:47
‪TYPO3\CMS\Backend\Form\Container\FlexFormSectionContainer\getLanguageService
‪getLanguageService()
Definition: FlexFormSectionContainer.php:158
‪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\Backend\Form\Container\AbstractContainer\getBackendUserAuthentication
‪getBackendUserAuthentication()
Definition: AbstractContainer.php:149
‪TYPO3\CMS\Backend\Form\AbstractNode\$data
‪array $data
Definition: AbstractNode.php:35
‪TYPO3\CMS\Backend\Form\Container\AbstractContainer
Definition: AbstractContainer.php:29
‪TYPO3\CMS\Backend\Form\Container\FlexFormSectionContainer\__construct
‪__construct(private readonly IconFactory $iconFactory,)
Definition: FlexFormSectionContainer.php:35
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Form\Container\FlexFormSectionContainer
Definition: FlexFormSectionContainer.php:34
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪initializeResultArray()
Definition: AbstractNode.php:77