a6d984ab53eeb1c5300daf09ed70cdc54da7b698
[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 backported from the TYPO3 Flow package "TYPO3.Fluid".
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use \TYPO3\CMS\Backend\Utility\BackendUtility;
20 use \TYPO3\CMS\Backend\Utility\IconUtility;
21
22 /**
23 * View helper which return page info icon as known from TYPO3 backend modules
24 * Note: This view helper is experimental!
25 *
26 * = Examples =
27 *
28 * <code>
29 * <f:be.pageInfo />
30 * </code>
31 * <output>
32 * Page info icon with context menu
33 * </output>
34 */
35 class PageInfoViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper {
36
37 /**
38 * Render javascript in header
39 *
40 * @return string the rendered page info icon
41 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate::getPageInfo() Note: can't call this method as it's protected!
42 */
43 public function render() {
44 $doc = $this->getDocInstance();
45 $id = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id');
46 $pageRecord = BackendUtility::readPageAccess($id, $GLOBALS['BE_USER']->getPagePermsClause(1));
47 // Add icon with clickmenu, etc:
48 if ($pageRecord['uid']) {
49 // If there IS a real page
50 $alttext = BackendUtility::getRecordIconAltText($pageRecord, 'pages');
51 $iconImg = IconUtility::getSpriteIconForRecord('pages', $pageRecord, array('title' => htmlspecialchars($alttext)));
52 // Make Icon:
53 $theIcon = $doc->wrapClickMenuOnIcon($iconImg, 'pages', $pageRecord['uid']);
54 } else {
55 // On root-level of page tree
56 // Make Icon
57 $iconImg = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_website.gif') . ' alt="' . htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) . '" />';
58 if ($GLOBALS['BE_USER']->user['admin']) {
59 $theIcon = $doc->wrapClickMenuOnIcon($iconImg, 'pages', 0);
60 } else {
61 $theIcon = $iconImg;
62 }
63 }
64 // Setting icon with clickmenu + uid
65 $pageInfo = $theIcon . '<em>[pid: ' . $pageRecord['uid'] . ']</em>';
66 return $pageInfo;
67 }
68
69 }