82b9e7327838d3ee7266cfb3cb938a472c0b1dca
[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 script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * *
12 * This script is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15 * General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with the script. *
19 * If not, see http://www.gnu.org/licenses/lgpl.html *
20 * *
21 * The TYPO3 project - inspiring people to share! *
22 * */
23
24 use TYPO3\CMS\Backend\Template\DocumentTemplate;
25 use TYPO3\CMS\Backend\Utility\BackendUtility;
26 use TYPO3\CMS\Backend\Utility\IconUtility;
27 use TYPO3\CMS\Core\Utility\GeneralUtility;
28 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
29 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
30
31 /**
32 * View helper which return page info icon as known from TYPO3 backend modules
33 * Note: This view helper is experimental!
34 *
35 * = Examples =
36 *
37 * <code>
38 * <f:be.pageInfo />
39 * </code>
40 * <output>
41 * Page info icon with context menu
42 * </output>
43 */
44 class PageInfoViewHelper extends AbstractBackendViewHelper implements CompilableInterface {
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 return self::renderStatic(
54 array(),
55 $this->buildRenderChildrenClosure(),
56 $this->renderingContext
57 );
58 }
59
60 /**
61 * @param array $arguments
62 * @param callable $renderChildrenClosure
63 * @param RenderingContextInterface $renderingContext
64 *
65 * @return string
66 */
67 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
68 $doc = GeneralUtility::makeInstance(DocumentTemplate::class);
69 $id = GeneralUtility::_GP('id');
70 $pageRecord = BackendUtility::readPageAccess($id, $GLOBALS['BE_USER']->getPagePermsClause(1));
71 // Add icon with clickmenu, etc:
72 if ($pageRecord['uid']) {
73 // If there IS a real page
74 $alttext = BackendUtility::getRecordIconAltText($pageRecord, 'pages');
75 $iconImg = IconUtility::getSpriteIconForRecord('pages', $pageRecord, array('title' => htmlspecialchars($alttext)));
76 // Make Icon:
77 $theIcon = $doc->wrapClickMenuOnIcon($iconImg, 'pages', $pageRecord['uid']);
78 } else {
79 // On root-level of page tree
80 // Make Icon
81 $iconImg = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_website.gif') . ' alt="' . htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) . '" />';
82 if ($GLOBALS['BE_USER']->user['admin']) {
83 $theIcon = $doc->wrapClickMenuOnIcon($iconImg, 'pages', 0);
84 } else {
85 $theIcon = $iconImg;
86 }
87 }
88 // Setting icon with clickmenu + uid
89 return $theIcon . '<em>[pid: ' . $pageRecord['uid'] . ']</em>';
90 }
91 }