[CLEANUP] Use Permission constants consistently
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / PageInfoViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Be;
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\Core\Imaging\Icon;
19 use TYPO3\CMS\Core\Imaging\IconFactory;
20 use TYPO3\CMS\Core\Type\Bitmask\Permission;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
23
24 /**
25 * View helper which return page info icon as known from TYPO3 backend modules
26 * Note: This view helper is experimental!
27 *
28 * = Examples =
29 *
30 * <code>
31 * <f:be.pageInfo />
32 * </code>
33 * <output>
34 * Page info icon with context menu
35 * </output>
36 */
37 class PageInfoViewHelper extends AbstractBackendViewHelper
38 {
39
40 /**
41 * This view helper renders HTML, thus output must not be escaped
42 *
43 * @var bool
44 */
45 protected $escapeOutput = false;
46
47 /**
48 * Render javascript in header
49 *
50 * @return string the rendered page info icon
51 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate::getPageInfo() Note: can't call this method as it's protected!
52 */
53 public function render()
54 {
55 return static::renderStatic(
56 [],
57 $this->buildRenderChildrenClosure(),
58 $this->renderingContext
59 );
60 }
61
62 /**
63 * @param array $arguments
64 * @param \Closure $renderChildrenClosure
65 * @param RenderingContextInterface $renderingContext
66 *
67 * @return string
68 */
69 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
70 {
71 $id = GeneralUtility::_GP('id');
72 $pageRecord = BackendUtility::readPageAccess($id, $GLOBALS['BE_USER']->getPagePermsClause(Permission::PAGE_SHOW));
73 // Add icon with context menu, etc:
74 /** @var IconFactory $iconFactory */
75 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
76 if ($pageRecord['uid']) {
77 // If there IS a real page
78 $altText = BackendUtility::getRecordIconAltText($pageRecord, 'pages');
79 $theIcon = '<span title="' . $altText . '">' . $iconFactory->getIconForRecord('pages', $pageRecord, Icon::SIZE_SMALL)->render() . '</span>';
80 // Make Icon:
81 $theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, 'pages', $pageRecord['uid']);
82
83 // Setting icon with context menu + uid
84 $theIcon .= ' <em>[PID: ' . $pageRecord['uid'] . ']</em>';
85 } else {
86 // On root-level of page tree
87 // Make Icon
88 $theIcon = '<span title="' . htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) . '">' . $iconFactory->getIcon('apps-pagetree-page-domain', Icon::SIZE_SMALL)->render() . '</span>';
89 if ($GLOBALS['BE_USER']->isAdmin()) {
90 $theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, 'pages');
91 }
92 }
93 return $theIcon;
94 }
95 }