SpriteIconForRecordViewHelper.php 3.06 KB
Newer Older
1
<?php
2

3
4
namespace TYPO3\CMS\Beuser\ViewHelpers;

5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
9
10
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
11
 *
12
13
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
16
 * The TYPO3 project - inspiring people to share!
 */
17

18
19
20
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22
use TYPO3\CMS\Extbase\Domain\Model\BackendUser;
use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
23
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
24

25
26
/**
 * Views sprite icon for a record (object)
27
 * @internal
28
 */
29
class SpriteIconForRecordViewHelper extends AbstractBackendViewHelper
30
{
31
32
33
34
35
36
37
    /**
     * As this ViewHelper renders HTML, the output must not be escaped.
     *
     * @var bool
     */
    protected $escapeOutput = false;

38
39
40
41
42
43
44
45
46
47
    /**
     * Initializes the arguments
     */
    public function initializeArguments()
    {
        parent::initializeArguments();
        $this->registerArgument('table', 'string', '', true);
        $this->registerArgument('object', 'object', '', true);
    }

48
49
50
51
52
53
    /**
     * Displays spriteIcon for database table and object
     *
     * @return string
     * @see IconFactory::getIconForRecord()
     */
54
    public function render()
55
    {
56
        return static::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext);
57
    }
58

59
60
    /**
     * @param array $arguments
61
     * @param \Closure $renderChildrenClosure
62
63
64
     * @param RenderingContextInterface $renderingContext
     *
     * @return string
65
     * @throws \Exception
66
67
68
69
70
     */
    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
    {
        $object = $arguments['object'];
        $table = $arguments['table'];
71

72
73
74
        if (!is_object($object) || !method_exists($object, 'getUid')) {
            return '';
        }
75
        $row = [
76
77
78
            'uid' => $object->getUid(),
            'startTime' => false,
            'endTime' => false
79
        ];
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
        if (method_exists($object, 'getIsDisabled')) {
            $row['disable'] = $object->getIsDisabled();
        }
        if (method_exists($object, 'getHidden')) {
            $row['hidden'] = $object->getHidden();
        }
        if ($table === 'be_users' && $object instanceof BackendUser) {
            $row['admin'] = $object->getIsAdministrator();
        }
        if (method_exists($object, 'getStartDateAndTime')) {
            $row['startTime'] = $object->getStartDateAndTime();
        }
        if (method_exists($object, 'getEndDateAndTime')) {
            $row['endTime'] = $object->getEndDateAndTime();
        }
        /** @var IconFactory $iconFactory */
        $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
        return $iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render();
    }
99
}