[TASK] Move ViewHelper arguments to initializeArguments() in ext:belog
[Packages/TYPO3.CMS.git] / typo3 / sysext / belog / Classes / ViewHelpers / HistoryEntryViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Belog\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\BackendUtility;
18 use TYPO3\CMS\Belog\Domain\Model\HistoryEntry;
19 use TYPO3\CMS\Belog\Domain\Repository\HistoryEntryRepository;
20 use TYPO3\CMS\Core\Imaging\Icon;
21 use TYPO3\CMS\Core\Imaging\IconFactory;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23 use TYPO3\CMS\Extbase\Object\ObjectManager;
24 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
25 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
26 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
27 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
28
29 /**
30 * Get history entry from for log entry
31 * @internal
32 */
33 class HistoryEntryViewHelper extends AbstractViewHelper
34 {
35 /**
36 * As this ViewHelper renders HTML, the output must not be escaped.
37 *
38 * @var bool
39 */
40 protected $escapeOutput = false;
41
42 /**
43 * Initializes the arguments
44 */
45 public function initializeArguments()
46 {
47 parent::initializeArguments();
48 $this->registerArgument('uid', 'int', 'Uid of the log entry', true);
49 }
50
51 /**
52 * Get system history record
53 *
54 * @return string Formatted history entry if one exists, else empty string
55 */
56 public function render()
57 {
58 return static::renderStatic(
59 $this->arguments,
60 $this->buildRenderChildrenClosure(),
61 $this->renderingContext
62 );
63 }
64
65 /**
66 * @param array $arguments
67 * @param \Closure $renderChildrenClosure
68 * @param RenderingContextInterface $renderingContext
69 *
70 * @return string
71 * @throws \InvalidArgumentException
72 */
73 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
74 {
75 if (!$renderingContext instanceof RenderingContext) {
76 throw new \InvalidArgumentException('The given rendering context is not of type "TYPO3\CMS\Fluid\Core\Rendering\RenderingContext"', 1468363945);
77 }
78 /** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */
79 $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
80 /** @var \TYPO3\CMS\Belog\Domain\Repository\HistoryEntryRepository $historyEntryRepository */
81 $historyEntryRepository = $objectManager->get(HistoryEntryRepository::class);
82 /** @var \TYPO3\CMS\Belog\Domain\Model\HistoryEntry $historyEntry */
83 $historyEntry = $historyEntryRepository->findOneBySysLogUid($arguments['uid']);
84 $controllerContext = $renderingContext->getControllerContext();
85 /** @var IconFactory $iconFactory */
86 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
87
88 if (!$historyEntry instanceof HistoryEntry) {
89 return '';
90 }
91 $historyLabel = LocalizationUtility::translate(
92 'changesInFields',
93 $controllerContext->getRequest()->getControllerExtensionName(),
94 array($historyEntry->getFieldlist())
95 );
96 $titleLable = LocalizationUtility::translate(
97 'showHistory',
98 $controllerContext->getRequest()->getControllerExtensionName()
99 );
100 $historyIcon = $iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render();
101 $historyHref = BackendUtility::getModuleUrl(
102 'record_history',
103 array(
104 'sh_uid' => $historyEntry->getUid(),
105 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'),
106 )
107 );
108 $historyLink = '<a href="' . htmlspecialchars($historyHref) . '" title="' . htmlspecialchars($titleLable) . '">' . $historyIcon . '</a>';
109 return htmlspecialchars($historyLabel) . '&nbsp;' . $historyLink;
110 }
111 }