‪TYPO3CMS  ‪main
FlexFormContainerContainer.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;
22 
29 {
30  public function ‪__construct(
31  private readonly ‪IconFactory $iconFactory,
32  ) {}
33 
39  public function ‪render(): array
40  {
41  $languageService = $this->‪getLanguageService();
42 
43  $table = $this->data['tableName'];
44  $row = $this->data['databaseRow'];
45  $fieldName = $this->data['fieldName'];
46  $flexFormFormPrefix = $this->data['flexFormFormPrefix'];
47  $flexFormDataStructureArray = $this->data['flexFormDataStructureArray'];
48 
49  $flexFormContainerIdentifier = $this->data['flexFormContainerIdentifier'];
50  $actionFieldName = 'data[' . $table . '][' . $row['uid'] . '][' . $fieldName . ']'
51  . $flexFormFormPrefix
52  . '[' . $flexFormContainerIdentifier . ']'
53  . '[_ACTION]';
54 
55  $moveAndDeleteContent = [];
56  $userHasAccessToDefaultLanguage = $this->‪getBackendUserAuthentication()->checkLanguageAccess(0);
57  if ($userHasAccessToDefaultLanguage) {
58  $moveAndDeleteContent[] = ''
59  . '<button type="button" class="btn btn-default t3js-delete">'
60  . $this->iconFactory->getIcon('actions-edit-delete', IconSize::SMALL)->setTitle($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:delete'))->render()
61  . '</button>';
62  $moveAndDeleteContent[] = ''
63  . '<button type="button" class="btn btn-default t3js-sortable-handle sortableHandle">'
64  . $this->iconFactory->getIcon('actions-move-move', IconSize::SMALL)->setTitle($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:sortable.dragmove'))->render()
65  . '</button>';
66  }
67 
68  $options = ‪$this->data;
69  // Append container specific stuff to field prefix
70  $options['flexFormFormPrefix'] = $flexFormFormPrefix . '[' . $flexFormContainerIdentifier . '][' . $this->data['flexFormContainerName'] . '][el]';
71  $options['flexFormDataStructureArray'] = $flexFormDataStructureArray['el'];
72  $options['renderType'] = 'flexFormElementContainer';
73  $containerContentResult = $this->nodeFactory->create($options)->render();
74 
75  $containerTitle = '';
76  if (!empty(trim($flexFormDataStructureArray['title']))) {
77  $containerTitle = $languageService->sL(trim($flexFormDataStructureArray['title']));
78  }
79 
80  $resultArray = $this->‪initializeResultArray();
81 
82  $flexFormDomContainerId = sprintf('flexform-container-%s', $flexFormContainerIdentifier);
83  $parentSectionContainer = sprintf('flexform-section-container-%s-%s', $this->data['fieldName'], $this->data['flexFormFieldName']);
84  $containerAttributes = [
85  'class' => 'form-irre-object panel panel-default panel-condensed t3js-flex-section',
86  'data-parent' => $parentSectionContainer,
87  'data-flexform-container-id' => $flexFormContainerIdentifier,
88  ];
89 
90  $panelHeaderAttributes = [
91  'class' => 'panel-heading',
92  'data-bs-toggle' => 'flexform-inline',
93  'data-bs-target' => '#' . $flexFormDomContainerId,
94  ];
95 
96  $toggleAttributes = [
97  'class' => 'form-irre-header-cell form-irre-header-button',
98  'type' => 'button',
99  'aria-controls' => $flexFormDomContainerId,
100  'aria-expanded' => 'false',
101  ];
102 
103  $html = [];
104  $html[] = '<div ' . GeneralUtility::implodeAttributes($containerAttributes, true) . '>';
105  $html[] = '<div ' . GeneralUtility::implodeAttributes($panelHeaderAttributes, true) . '>';
106  $html[] = '<div class="form-irre-header collapsed">';
107  $html[] = '<div class="form-irre-header-cell form-irre-header-icon">';
108  $html[] = '<span class="caret"></span>';
109  $html[] = '</div>';
110  $html[] = '<button ' . GeneralUtility::implodeAttributes($toggleAttributes, true) . '>';
111  $html[] = '<div class="form-irre-header-cell form-irre-header-body">';
112  $html[] = htmlspecialchars($containerTitle);
113  $html[] = '<output class="content-preview"></output>';
114  $html[] = '</div>';
115  $html[] = '</button>';
116  $html[] = '<div class="form-irre-header-cell form-irre-header-control t3js-formengine-irre-control">';
117  $html[] = '<div class="btn-group btn-group-sm">';
118  $html[] = implode(LF, $moveAndDeleteContent);
119  $html[] = '</div>';
120  $html[] = '</div>';
121  $html[] = '</div>';
122  $html[] = '</div>';
123  $html[] = '<div id="' . htmlspecialchars($flexFormDomContainerId) . '" class="panel-collapse collapse t3js-flex-section-content">';
124  $html[] = $containerContentResult['html'];
125  $html[] = '</div>';
126  $html[] = '<input class="t3js-flex-control-action" type="hidden" name="' . htmlspecialchars($actionFieldName) . '" value="" />';
127  $html[] = '</div>';
128 
129  $resultArray['html'] = implode(LF, $html);
130  $resultArray = $this->‪mergeChildReturnIntoExistingResult($resultArray, $containerContentResult, false);
131 
132  return $resultArray;
133  }
134 
136  {
137  return ‪$GLOBALS['LANG'];
138  }
139 }
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:104
‪TYPO3\CMS\Backend\Form\Container
Definition: AbstractContainer.php:16
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪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\FlexFormContainerContainer\getLanguageService
‪getLanguageService()
Definition: FlexFormContainerContainer.php:135
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Form\Container\FlexFormContainerContainer\__construct
‪__construct(private readonly IconFactory $iconFactory,)
Definition: FlexFormContainerContainer.php:30
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Backend\Form\Container\FlexFormContainerContainer\render
‪array render()
Definition: FlexFormContainerContainer.php:39
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Form\Container\FlexFormContainerContainer
Definition: FlexFormContainerContainer.php:29
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪initializeResultArray()
Definition: AbstractNode.php:77