TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
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 
25 
29 abstract class AbstractContainer extends AbstractNode
30 {
36  protected $nodeFactory;
37 
44  public function __construct(NodeFactory $nodeFactory, array $data)
45  {
46  parent::__construct($nodeFactory, $data);
47  $this->nodeFactory = $nodeFactory;
48  }
49 
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 [
68  'fieldName' => $fieldArray[0],
69  'fieldLabel' => $fieldArray[1] ?: null,
70  'paletteName' => $fieldArray[2] ?: null,
71  ];
72  }
73 
82  protected function renderTabMenu(array $menuItems, $domId, $defaultTabIndex = 1)
83  {
84  $templatePath = ExtensionManagementUtility::extPath('backend')
85  . 'Resources/Private/Templates/DocumentTemplate/';
86 
87  $view = GeneralUtility::makeInstance(StandaloneView::class);
88  $view->setTemplatePathAndFilename($templatePath . 'Tabs.html');
89  $view->setPartialRootPaths([$templatePath . 'Partials']);
90  $view->assignMultiple([
91  'id' => $domId,
92  'items' => $menuItems,
93  'defaultTabIndex' => $defaultTabIndex,
94  'wrapContent' => false,
95  'storeLastActiveTab' => true,
96  ]);
97  return $view->render();
98  }
99 
108  protected function previewFieldValue($value, $config, $field = '')
109  {
110  if ($config['config']['type'] === 'group' && ($config['config']['internal_type'] === 'file' || $config['config']['internal_type'] === 'file_reference')) {
111  // Ignore upload folder if internal_type is file_reference
112  if ($config['config']['internal_type'] === 'file_reference') {
113  $config['config']['uploadfolder'] = '';
114  }
115  $table = 'tt_content';
116  // Making the array of file items:
117  $itemArray = GeneralUtility::trimExplode(',', $value, true);
118  // Showing thumbnails:
119  $imgs = [];
120  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
121  foreach ($itemArray as $imgRead) {
122  $imgParts = explode('|', $imgRead);
123  $imgPath = rawurldecode($imgParts[0]);
124  $rowCopy = [];
125  $rowCopy[$field] = $imgPath;
126  // Icon + click menu:
127  $absFilePath = GeneralUtility::getFileAbsFileName($config['config']['uploadfolder'] ? $config['config']['uploadfolder'] . '/' . $imgPath : $imgPath);
128  $fileInformation = pathinfo($imgPath);
129  $title = $fileInformation['basename'] . ($absFilePath && @is_file($absFilePath))
130  ? ' (' . GeneralUtility::formatSize(filesize($absFilePath)) . ')'
131  : ' - FILE NOT FOUND!';
132  $fileIcon = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForFileExtension($fileInformation['extension'], Icon::SIZE_SMALL)->render() . '</span>';
133  $imgs[] =
134  '<span class="text-nowrap">' .
135  BackendUtility::thumbCode(
136  $rowCopy,
137  $table,
138  $field,
139  '',
140  '',
141  $config['config']['uploadfolder'], 0, ' align="middle"'
142  ) .
143  ($absFilePath ? BackendUtility::wrapClickMenuOnIcon($fileIcon, $absFilePath, 0, 1, '', '+copy,info,edit,view') : $fileIcon) .
144  $imgPath .
145  '</span>';
146  }
147  return implode('<br />', $imgs);
148  } else {
149  return nl2br(htmlspecialchars($value));
150  }
151  }
152 }
__construct(NodeFactory $nodeFactory, array $data)
renderTabMenu(array $menuItems, $domId, $defaultTabIndex=1)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static formatSize($sizeInBytes, $labels= '', $base=0)
static makeInstance($className,...$constructorArguments)
static wrapClickMenuOnIcon($content, $table, $uid=0, $listFrame=true, $addParams= '', $enDisItems= '', $returnTagParameters=false)
static getFileAbsFileName($filename, $_=null, $_2=null)