[BUGFIX] Use late static binding for compilable viewhelpers
[Packages/TYPO3.CMS.git] / typo3 / sysext / beuser / Classes / ViewHelpers / SpriteIconForRecordViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Beuser\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\Backend\Utility\IconUtility;
18 use TYPO3\CMS\Extbase\Domain\Model\BackendUser;
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 * Views sprite icon for a record (object)
25 *
26 * @author Felix Kopp <felix-source@phorax.com>
27 * @internal
28 */
29 class SpriteIconForRecordViewHelper extends AbstractBackendViewHelper implements CompilableInterface {
30
31 /**
32 * Displays spriteIcon for database table and object
33 *
34 * @param string $table
35 * @param object $object
36 * @return string
37 * @see \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord($table, $row)
38 */
39 public function render($table, $object) {
40 return static::renderStatic(
41 array(
42 'table' => $table,
43 'object' => $object
44 ),
45 $this->buildRenderChildrenClosure(),
46 $this->renderingContext
47 );
48 }
49
50 /**
51 * @param array $arguments
52 * @param callable $renderChildrenClosure
53 * @param RenderingContextInterface $renderingContext
54 *
55 * @return string
56 * @throws Exception
57 */
58 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
59 $object = $arguments['object'];
60 $table = $arguments['table'];
61
62 if (!is_object($object) || !method_exists($object, 'getUid')) {
63 return '';
64 }
65 $row = array(
66 'uid' => $object->getUid(),
67 'startTime' => FALSE,
68 'endTime' => FALSE
69 );
70 if (method_exists($object, 'getIsDisabled')) {
71 $row['disable'] = $object->getIsDisabled();
72 }
73 if (method_exists($object, 'getHidden')) {
74 $row['hidden'] = $object->getHidden();
75 }
76 if ($table === 'be_users' && $object instanceof BackendUser) {
77 $row['admin'] = $object->getIsAdministrator();
78 }
79 if (method_exists($object, 'getStartDateAndTime')) {
80 $row['startTime'] = $object->getStartDateAndTime();
81 }
82 if (method_exists($object, 'getEndDateAndTime')) {
83 $row['endTime'] = $object->getEndDateAndTime();
84 }
85 return IconUtility::getSpriteIconForRecord($table, $row);
86 }
87
88 }