[FEATURE] Add new ViewHelper for record icons
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / ViewHelpers / IconForRecordViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Core\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\Imaging\Icon;
18 use TYPO3\CMS\Core\Imaging\IconFactory;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
21
22 /**
23 * Displays icon for record
24 */
25 class IconForRecordViewHelper extends AbstractViewHelper
26 {
27 /**
28 * View helper returns HTML, thus we need to disable output escaping
29 *
30 * @var bool
31 */
32 protected $escapeOutput = false;
33
34 /**
35 * Initializes the arguments
36 */
37 public function initializeArguments()
38 {
39 $this->registerArgument('table', 'string', 'the table for the record icon', true);
40 $this->registerArgument('row', 'array', 'the record row', true);
41 $this->registerArgument('size', 'string', 'the icon size', false, Icon::SIZE_SMALL);
42 $this->registerArgument('alternativeMarkupIdentifier', 'string', 'alternative markup identifier', false, null);
43 }
44
45 /**
46 * Prints icon html for record icon
47 *
48 * @return string
49 */
50 public function render() : string
51 {
52 $table = $this->arguments['table'];
53 $size = $this->arguments['size'];
54 $row = $this->arguments['row'];
55 $alternativeMarkupIdentifier = $this->arguments['alternativeMarkupIdentifier'];
56 /** @var IconFactory $iconFactory */
57 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
58 return $iconFactory->getIconForRecord($table, $row, $size)->render($alternativeMarkupIdentifier);
59 }
60 }