TYPO3  7.6
AbstractContainer.php
Go to the documentation of this file.
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 
24 
28 abstract class AbstractContainer extends AbstractNode
29 {
35  protected $nodeFactory;
36 
43  public function __construct(NodeFactory $nodeFactory, array $data)
44  {
45  parent::__construct($nodeFactory, $data);
46  $this->nodeFactory = $nodeFactory;
47  }
48 
60  protected function explodeSingleFieldShowItemConfiguration($field)
61  {
62  $fieldArray = GeneralUtility::trimExplode(';', $field);
63  if (empty($fieldArray[0])) {
64  throw new \RuntimeException('Field must not be empty', 1426448465);
65  }
66  return array(
67  'fieldName' => $fieldArray[0],
68  'fieldLabel' => $fieldArray[1] ?: null,
69  'paletteName' => $fieldArray[2] ?: null,
70  );
71  }
72 
81  protected function renderTabMenu(array $menuItems, $domId, $defaultTabIndex = 1)
82  {
83  $templatePathAndFileName = 'EXT:backend/Resources/Private/Templates/DocumentTemplate/Tabs.html';
84  $view = GeneralUtility::makeInstance(StandaloneView::class);
85  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templatePathAndFileName));
86  $view->assignMultiple(array(
87  'id' => $domId,
88  'items' => $menuItems,
89  'defaultTabIndex' => $defaultTabIndex,
90  'wrapContent' => false,
91  'storeLastActiveTab' => true,
92  ));
93  return $view->render();
94  }
95 
104  protected function previewFieldValue($value, $config, $field = '')
105  {
106  if ($config['config']['type'] === 'group' && ($config['config']['internal_type'] === 'file' || $config['config']['internal_type'] === 'file_reference')) {
107  // Ignore upload folder if internal_type is file_reference
108  if ($config['config']['internal_type'] === 'file_reference') {
109  $config['config']['uploadfolder'] = '';
110  }
111  $table = 'tt_content';
112  // Making the array of file items:
113  $itemArray = GeneralUtility::trimExplode(',', $value, true);
114  // Showing thumbnails:
115  $thumbnail = '';
116  $imgs = array();
117  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
118  foreach ($itemArray as $imgRead) {
119  $imgParts = explode('|', $imgRead);
120  $imgPath = rawurldecode($imgParts[0]);
121  $rowCopy = array();
122  $rowCopy[$field] = $imgPath;
123  // Icon + click menu:
124  $absFilePath = GeneralUtility::getFileAbsFileName($config['config']['uploadfolder'] ? $config['config']['uploadfolder'] . '/' . $imgPath : $imgPath);
125  $fileInformation = pathinfo($imgPath);
126  $title = $fileInformation['basename'] . ($absFilePath && @is_file($absFilePath))
127  ? ' (' . GeneralUtility::formatSize(filesize($absFilePath)) . ')'
128  : ' - FILE NOT FOUND!';
129  $fileIcon = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForFileExtension($fileInformation['extension'], Icon::SIZE_SMALL)->render() . '</span>';
130  $imgs[] =
131  '<span class="text-nowrap">' .
132  BackendUtility::thumbCode(
133  $rowCopy,
134  $table,
135  $field,
136  '',
137  'thumbs.php',
138  $config['config']['uploadfolder'], 0, ' align="middle"'
139  ) .
140  ($absFilePath ? BackendUtility::wrapClickMenuOnIcon($fileIcon, $absFilePath, 0, 1, '', '+copy,info,edit,view') : $fileIcon) .
141  $imgPath .
142  '</span>';
143  }
144  return implode('<br />', $imgs);
145  } else {
146  return nl2br(htmlspecialchars($value));
147  }
148  }
149 }