[TASK] Replace sprite icon "actions-document-history-open" with the new IconFactory
[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\Imaging\Icon;
22 use TYPO3\CMS\Core\Imaging\IconFactory;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24 use TYPO3\CMS\Extbase\Object\ObjectManager;
25 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
26 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
27 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
28 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
29
30 /**
31 * Get history entry from for log entry
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 /** @var IconFactory $iconFactory */
69 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
70
71 if (!$historyEntry instanceof HistoryEntry) {
72 return '';
73 }
74 $historyLabel = LocalizationUtility::translate(
75 'changesInFields',
76 $controllerContext->getRequest()->getControllerExtensionName(),
77 array($historyEntry->getFieldlist())
78 );
79 $titleLable = LocalizationUtility::translate(
80 'showHistory',
81 $controllerContext->getRequest()->getControllerExtensionName()
82 );
83 $historyIcon = $iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL);
84 $historyHref = BackendUtility::getModuleUrl(
85 'record_history',
86 array(
87 'sh_uid' => $historyEntry->getUid(),
88 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'),
89 )
90 );
91 $historyLink = '<a href="' . htmlspecialchars($historyHref) . '" title="' . htmlspecialchars($titleLable) . '">' . $historyIcon . '</a>';
92 return $historyLabel . '&nbsp;' . $historyLink;
93 }
94
95 }