SpriteIconForRecordViewHelper.php 2.66 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
use TYPO3\CMS\Extbase\Domain\Model\BackendUser;
21
use TYPO3\CMS\Extbase\Object\ObjectManager;
22
23
24
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
25

26
27
/**
 * Views sprite icon for a record (object)
28
 * @internal
29
 */
30
class SpriteIconForRecordViewHelper extends AbstractBackendViewHelper implements CompilableInterface {
31
32
33
34
35
36
37

	/**
	 * Displays spriteIcon for database table and object
	 *
	 * @param string $table
	 * @param object $object
	 * @return string
38
	 * @see IconFactory::getIconForRecord()
39
40
	 */
	public function render($table, $object) {
41
		return static::renderStatic(
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
			array(
				'table' => $table,
				'object' => $object
			),
			$this->buildRenderChildrenClosure(),
			$this->renderingContext
		);
	}

	/**
	 * @param array $arguments
	 * @param callable $renderChildrenClosure
	 * @param RenderingContextInterface $renderingContext
	 *
	 * @return string
	 * @throws Exception
	 */
	static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
		$object = $arguments['object'];
		$table = $arguments['table'];

63
64
65
66
67
68
		if (!is_object($object) || !method_exists($object, 'getUid')) {
			return '';
		}
		$row = array(
			'uid' => $object->getUid(),
			'startTime' => FALSE,
69
			'endTime' => FALSE
70
71
72
73
		);
		if (method_exists($object, 'getIsDisabled')) {
			$row['disable'] = $object->getIsDisabled();
		}
74
75
76
		if (method_exists($object, 'getHidden')) {
			$row['hidden'] = $object->getHidden();
		}
77
		if ($table === 'be_users' && $object instanceof BackendUser) {
78
79
80
81
82
83
84
85
			$row['admin'] = $object->getIsAdministrator();
		}
		if (method_exists($object, 'getStartDateAndTime')) {
			$row['startTime'] = $object->getStartDateAndTime();
		}
		if (method_exists($object, 'getEndDateAndTime')) {
			$row['endTime'] = $object->getEndDateAndTime();
		}
86
87
88
		/** @var IconFactory $iconFactory */
		$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
		return $iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render();
89
90
91
	}

}