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