[BUGFIX] FormEngine: Inline getDynamicTabMenu
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / Container / AbstractContainer.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\Backend\Form\NodeFactory;
18 use TYPO3\CMS\Backend\Form\Utility\FormEngineUtility;
19 use TYPO3\CMS\Core\Imaging\Icon;
20 use TYPO3\CMS\Core\Imaging\IconFactory;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Backend\Form\AbstractNode;
23 use TYPO3\CMS\Backend\Utility\BackendUtility;
24 use TYPO3\CMS\Fluid\View\StandaloneView;
25
26 /**
27 * Abstract container has various methods used by the container classes
28 */
29 abstract class AbstractContainer extends AbstractNode
30 {
31 /**
32 * Instance of the node factory to create sub elements and container.
33 *
34 * @var NodeFactory
35 */
36 protected $nodeFactory;
37
38 /**
39 * Container objects give $nodeFactory down to other containers.
40 *
41 * @param NodeFactory $nodeFactory
42 * @param array $data
43 */
44 public function __construct(NodeFactory $nodeFactory, array $data)
45 {
46 parent::__construct($nodeFactory, $data);
47 $this->nodeFactory = $nodeFactory;
48 }
49
50 /**
51 * A single field of TCA 'types' 'showitem' can have four semicolon separated configuration options:
52 * fieldName: Name of the field to be found in TCA 'columns' section
53 * fieldLabel: An alternative field label
54 * paletteName: Name of a palette to be found in TCA 'palettes' section that is rendered after this field
55 * extra: Special configuration options of this field
56 *
57 * @param string $field Semicolon separated field configuration
58 * @throws \RuntimeException
59 * @return array
60 */
61 protected function explodeSingleFieldShowItemConfiguration($field)
62 {
63 $fieldArray = GeneralUtility::trimExplode(';', $field);
64 if (empty($fieldArray[0])) {
65 throw new \RuntimeException('Field must not be empty', 1426448465);
66 }
67 return array(
68 'fieldName' => $fieldArray[0],
69 'fieldLabel' => $fieldArray[1] ?: null,
70 'paletteName' => $fieldArray[2] ?: null,
71 );
72 }
73
74 /**
75 * Render tabs with label and content. Used by TabsContainer and FlexFormTabsContainer.
76 * Re-uses the template Tabs.html which is also used by ModuleTemplate.php.
77 *
78 * @param array $menuItems Tab elements, each element is an array with "label" and "content"
79 * @param string $domId DOM id attribute, will be appended with an iteration number per tab.
80 * @return string
81 */
82 protected function renderTabMenu(array $menuItems, $domId, $defaultTabIndex = 1)
83 {
84 $templatePathAndFileName = 'EXT:backend/Resources/Private/Templates/DocumentTemplate/Tabs.html';
85 $view = GeneralUtility::makeInstance(StandaloneView::class);
86 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templatePathAndFileName));
87 $view->assignMultiple(array(
88 'id' => $domId,
89 'items' => $menuItems,
90 'defaultTabIndex' => $defaultTabIndex,
91 'wrapContent' => false,
92 'storeLastActiveTab' => true,
93 ));
94 return $view->render();
95 }
96
97 /**
98 * Rendering preview output of a field value which is not shown as a form field but just outputted.
99 *
100 * @param string $value The value to output
101 * @param array $config Configuration for field.
102 * @param string $field Name of field.
103 * @return string HTML formatted output
104 */
105 protected function previewFieldValue($value, $config, $field = '')
106 {
107 if ($config['config']['type'] === 'group' && ($config['config']['internal_type'] === 'file' || $config['config']['internal_type'] === 'file_reference')) {
108 // Ignore upload folder if internal_type is file_reference
109 if ($config['config']['internal_type'] === 'file_reference') {
110 $config['config']['uploadfolder'] = '';
111 }
112 $table = 'tt_content';
113 // Making the array of file items:
114 $itemArray = GeneralUtility::trimExplode(',', $value, true);
115 // Showing thumbnails:
116 $thumbnail = '';
117 $imgs = array();
118 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
119 foreach ($itemArray as $imgRead) {
120 $imgParts = explode('|', $imgRead);
121 $imgPath = rawurldecode($imgParts[0]);
122 $rowCopy = array();
123 $rowCopy[$field] = $imgPath;
124 // Icon + click menu:
125 $absFilePath = GeneralUtility::getFileAbsFileName($config['config']['uploadfolder'] ? $config['config']['uploadfolder'] . '/' . $imgPath : $imgPath);
126 $fileInformation = pathinfo($imgPath);
127 $title = $fileInformation['basename'] . ($absFilePath && @is_file($absFilePath))
128 ? ' (' . GeneralUtility::formatSize(filesize($absFilePath)) . ')'
129 : ' - FILE NOT FOUND!';
130 $fileIcon = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForFileExtension($fileInformation['extension'], Icon::SIZE_SMALL)->render() . '</span>';
131 $imgs[] =
132 '<span class="text-nowrap">' .
133 BackendUtility::thumbCode(
134 $rowCopy,
135 $table,
136 $field,
137 '',
138 'thumbs.php',
139 $config['config']['uploadfolder'], 0, ' align="middle"'
140 ) .
141 ($absFilePath ? BackendUtility::wrapClickMenuOnIcon($fileIcon, $absFilePath, 0, 1, '', '+copy,info,edit,view') : $fileIcon) .
142 $imgPath .
143 '</span>';
144 }
145 return implode('<br />', $imgs);
146 } else {
147 return nl2br(htmlspecialchars($value));
148 }
149 }
150 }