TYPO3 CMS  TYPO3_7-6
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 
23 
32 {
39  public function render(\TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation $documentTranslation)
40  {
41  return static::renderStatic(
42  [
43  'documentTranslation' => $documentTranslation,
44  ],
46  $this->renderingContext
47  );
48  }
49 
60  {
62  $documentTranslation = $arguments['documentTranslation'];
63 
65  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
66  $emptyIcon = $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render();
67  $icons = [
68  'html' => '<a class="btn btn-default disabled">' . $emptyIcon . '</a>',
69  'pdf' => '<a class="btn btn-default disabled">' . $emptyIcon . '</a>',
70  'sxw' => '<a class="btn btn-default disabled">' . $emptyIcon . '</a>'
71  ];
72  $formats = $documentTranslation->getFormats();
73 
74  foreach ($formats as $format) {
75  $output = '';
77  $output .= '<a ';
78 
79  $uri = '../' . $format->getPath();
80  $documentFormat = $format->getFormat();
81  $extension = substr($uri, strrpos($uri, '.') + 1);
82  if (strlen($extension) < 5) {
83  // This is direct link to a file
84  $output .= 'href="' . $uri . '" class="btn btn-default"';
85  $iconHtml = static::getIconForFileExtension($extension, $iconFactory);
86  } else {
87  $output .= 'href="#" onclick="top.TYPO3.Backend.ContentContainer.setUrl(' . GeneralUtility::quoteJSvalue($uri) . ')" class="btn btn-default"';
88  $iconHtml = static::getIconForFileExtension($documentFormat, $iconFactory);
89  }
90 
91  $xliff = 'LLL:EXT:documentation/Resources/Private/Language/locallang.xlf';
92  $title = sprintf(
93  $GLOBALS['LANG']->sL($xliff . ':tx_documentation_domain_model_documentformat.format.title'),
94  $documentFormat
95  );
96  $output .= ' title="' . htmlspecialchars($title) . '">';
97  $output .= $iconHtml . '</a>' . LF;
98  if ($documentFormat === 'json') {
99  // It should take over the place of sxw which will then never be used
100  $documentFormat = 'sxw';
101  }
102  $icons[$documentFormat] = $output;
103  }
104  return implode('', array_values($icons));
105  }
106 
114  protected static function getIconForFileExtension($extension, IconFactory $iconFactory)
115  {
116  switch ($extension) {
117  case 'html':
118  case 'pdf':
119  $iconHtml = $iconFactory->getIcon('actions-file-' . $extension, Icon::SIZE_SMALL)->render();
120  break;
121  case 'sxw':
122  $iconHtml = $iconFactory->getIcon('actions-file-openoffice', Icon::SIZE_SMALL)->render();
123  break;
124  case 'json':
125  $iconHtml = $iconFactory->getIcon('actions-system-extension-documentation', Icon::SIZE_SMALL)->render();
126  break;
127  default:
128  $iconHtml = $iconFactory->getIconForFileExtension($extension, Icon::SIZE_SMALL)->render();
129  }
130  return $iconHtml;
131  }
132 }
render(\TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation $documentTranslation)
getIconForFileExtension($fileExtension, $size=Icon::SIZE_DEFAULT, $overlayIdentifier=null)
static getIconForFileExtension($extension, IconFactory $iconFactory)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static renderStatic(array $arguments, \Closure $renderChildrenClosure, \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)