1<?php 2namespace 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 17use TYPO3\CMS\Backend\Utility\BackendUtility; 18use TYPO3\CMS\Core\Type\Bitmask\Permission; 19use TYPO3\CMS\Core\Utility\GeneralUtility; 20use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; 21 22/** 23 * ViewHelper which returns the current page path as known from TYPO3 backend modules. 24 * 25 * .. note:: 26 * This ViewHelper is experimental! 27 * 28 * Examples 29 * ======== 30 * 31 * Default:: 32 * 33 * <f:be.pagePath /> 34 * 35 * Current page path, prefixed with "Path:" and wrapped in a span with the class ``typo3-docheader-pagePath``. 36 */ 37class PagePathViewHelper extends AbstractBackendViewHelper 38{ 39 40 /** 41 * This ViewHelper renders HTML, thus output must not be escaped 42 * 43 * @var bool 44 */ 45 protected $escapeOutput = false; 46 47 /** 48 * Renders the current page path 49 * 50 * @return string the rendered page path 51 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate::getPagePath() 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 // Is this a real page 74 if ($pageRecord['uid']) { 75 $title = $pageRecord['_thePathFull']; 76 } else { 77 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']; 78 } 79 // Setting the path of the page 80 $pagePath = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.path')) . ': <span class="typo3-docheader-pagePath">'; 81 // crop the title to title limit (or 50, if not defined) 82 $cropLength = empty($GLOBALS['BE_USER']->uc['titleLen']) ? 50 : $GLOBALS['BE_USER']->uc['titleLen']; 83 $croppedTitle = GeneralUtility::fixed_lgd_cs($title, -$cropLength); 84 if ($croppedTitle !== $title) { 85 $pagePath .= '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>'; 86 } else { 87 $pagePath .= htmlspecialchars($title); 88 } 89 $pagePath .= '</span>'; 90 return $pagePath; 91 } 92} 93