TYPO3 CMS  TYPO3_8-7
FormatsViewHelper.php
Go to the documentation of this file.
1 <?php
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 
33 {
35 
41  protected $escapeOutput = false;
42 
48  public function initializeArguments()
49  {
50  parent::initializeArguments();
51  $this->registerArgument('documentTranslation', DocumentTranslation::class, '', true);
52  }
53 
63  public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
64  {
66  $documentTranslation = $arguments['documentTranslation'];
67 
69  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
70  $emptyIcon = $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render();
71  $icons = [
72  'html' => '<a class="btn btn-default disabled">' . $emptyIcon . '</a>',
73  'pdf' => '<a class="btn btn-default disabled">' . $emptyIcon . '</a>',
74  'sxw' => '<a class="btn btn-default disabled">' . $emptyIcon . '</a>'
75  ];
76  $formats = $documentTranslation->getFormats();
77 
78  foreach ($formats as $format) {
79  $output = '';
81  $output .= '<a ';
82 
83  $uri = '../' . $format->getPath();
84  $documentFormat = $format->getFormat();
85  $extension = substr($uri, strrpos($uri, '.') + 1);
86  if (strlen($extension) < 5) {
87  // This is direct link to a file
88  $output .= 'href="' . htmlspecialchars($uri) . '" class="btn btn-default"';
89  $iconHtml = static::getIconForFileExtension($extension, $iconFactory);
90  } else {
91  $output .= 'href="#" onclick="top.TYPO3.Backend.ContentContainer.setUrl(' . GeneralUtility::quoteJSvalue($uri) . ')" class="btn btn-default"';
92  $iconHtml = static::getIconForFileExtension($documentFormat, $iconFactory);
93  }
94 
95  $xliff = 'LLL:EXT:documentation/Resources/Private/Language/locallang.xlf';
96  $title = sprintf(
97  $GLOBALS['LANG']->sL($xliff . ':tx_documentation_domain_model_documentformat.format.title'),
98  $documentFormat
99  );
100  $output .= ' title="' . htmlspecialchars($title) . '">';
101  $output .= $iconHtml . '</a>' . LF;
102  if ($documentFormat === 'json') {
103  // It should take over the place of sxw which will then never be used
104  $documentFormat = 'sxw';
105  }
106  $icons[$documentFormat] = $output;
107  }
108  return implode('', array_values($icons));
109  }
110 
118  protected static function getIconForFileExtension($extension, IconFactory $iconFactory)
119  {
120  switch ($extension) {
121  case 'html':
122  case 'pdf':
123  $iconHtml = $iconFactory->getIcon('actions-file-' . $extension, Icon::SIZE_SMALL)->render();
124  break;
125  case 'sxw':
126  $iconHtml = $iconFactory->getIcon('actions-file-openoffice', Icon::SIZE_SMALL)->render();
127  break;
128  case 'json':
129  $iconHtml = $iconFactory->getIcon('actions-system-extension-documentation', Icon::SIZE_SMALL)->render();
130  break;
131  default:
132  $iconHtml = $iconFactory->getIconForFileExtension($extension, Icon::SIZE_SMALL)->render();
133  }
134  return $iconHtml;
135  }
136 }
getIconForFileExtension($fileExtension, $size=Icon::SIZE_DEFAULT, $overlayIdentifier=null)
static getIconForFileExtension($extension, IconFactory $iconFactory)
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']