[CLEANUP] Code cleanup in ext:reports
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / Classes / ViewHelpers / IconViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Reports\ViewHelpers;
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\Core\Utility\ExtensionManagementUtility;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
20 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
21 use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
22
23 /**
24 * Render the icon of a report
25 *
26 * @internal
27 */
28 class IconViewHelper extends AbstractBackendViewHelper implements CompilableInterface
29 {
30 /**
31 * Renders the icon
32 *
33 * @param string $icon Icon to be used
34 * @param string $title Optional title
35 * @return string Content rendered image
36 */
37 public function render($icon, $title = '')
38 {
39 return static::renderStatic(
40 array(
41 'icon' => $icon,
42 'title' => $title,
43 ),
44 $this->buildRenderChildrenClosure(),
45 $this->renderingContext
46 );
47 }
48
49 /**
50 * @param array $arguments
51 * @param callable $renderChildrenClosure
52 * @param RenderingContextInterface $renderingContext
53 *
54 * @return string
55 */
56 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
57 {
58 $icon = $arguments['icon'];
59 $title = $arguments['title'];
60
61 if (!empty($icon)) {
62 $absIconPath = GeneralUtility::getFileAbsFilename($icon);
63 if (file_exists($absIconPath)) {
64 $icon = '../' . str_replace(PATH_site, '', $absIconPath);
65 }
66 } else {
67 $icon = ExtensionManagementUtility::extRelPath('reports') . 'ext_icon.png';
68 }
69 return '<img src="' . htmlspecialchars($icon) . '" width="16" height="16" title="' . htmlspecialchars($title) . '" alt="' . htmlspecialchars($title) . '" />';
70 }
71 }