[TASK] Call explicit render() on icon objects
[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\RenderingContextInterface;
26 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
27 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
28
29 /**
30 * Get history entry from for log entry
31 * @internal
32 */
33 class HistoryEntryViewHelper extends AbstractViewHelper implements CompilableInterface {
34
35 /**
36 * Get system history record
37 *
38 * @param int $uid Uid of the log entry
39 * @return string Formatted history entry if one exists, else empty string
40 */
41 public function render($uid) {
42 return static::renderStatic(
43 array(
44 'uid' => $uid
45 ),
46 $this->buildRenderChildrenClosure(),
47 $this->renderingContext
48 );
49 }
50
51 /**
52 * @param array $arguments
53 * @param callable $renderChildrenClosure
54 * @param RenderingContextInterface $renderingContext
55 *
56 * @return string
57 */
58 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
59 /** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */
60 $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
61 /** @var \TYPO3\CMS\Belog\Domain\Repository\HistoryEntryRepository $historyEntryRepository */
62 $historyEntryRepository = $objectManager->get(HistoryEntryRepository::class);
63 /** @var \TYPO3\CMS\Belog\Domain\Model\HistoryEntry $historyEntry */
64 $historyEntry = $historyEntryRepository->findOneBySysLogUid($arguments['uid']);
65 /** @var \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext */
66 $controllerContext = $renderingContext->getControllerContext();
67 /** @var IconFactory $iconFactory */
68 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
69
70 if (!$historyEntry instanceof HistoryEntry) {
71 return '';
72 }
73 $historyLabel = LocalizationUtility::translate(
74 'changesInFields',
75 $controllerContext->getRequest()->getControllerExtensionName(),
76 array($historyEntry->getFieldlist())
77 );
78 $titleLable = LocalizationUtility::translate(
79 'showHistory',
80 $controllerContext->getRequest()->getControllerExtensionName()
81 );
82 $historyIcon = $iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render();
83 $historyHref = BackendUtility::getModuleUrl(
84 'record_history',
85 array(
86 'sh_uid' => $historyEntry->getUid(),
87 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'),
88 )
89 );
90 $historyLink = '<a href="' . htmlspecialchars($historyHref) . '" title="' . htmlspecialchars($titleLable) . '">' . $historyIcon . '</a>';
91 return $historyLabel . '&nbsp;' . $historyLink;
92 }
93
94 }