SpriteIconForRecordViewHelper.php 3.07 KB
Newer Older
1
<?php
2
3
namespace TYPO3\CMS\Beuser\ViewHelpers;

4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
8
9
 * 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.
10
 *
11
12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
15
 * The TYPO3 project - inspiring people to share!
 */
16

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

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

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

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

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

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
        if (!is_object($object) || !method_exists($object, 'getUid')) {
            return '';
        }
        $row = array(
            'uid' => $object->getUid(),
            'startTime' => false,
            'endTime' => false
        );
        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();
    }
98
}