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