a00c9834158a2010ef61d1de81327f91aef6c382
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / PagePathViewHelper.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\Utility\GeneralUtility;
19 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
20
21 /**
22 * View helper which returns the current page path as known from TYPO3 backend modules
23 * Note: This view helper is experimental!
24 *
25 * = Examples =
26 *
27 * <code>
28 * <f:be.pagePath />
29 * </code>
30 * <output>
31 * Current page path, prefixed with "Path:" and wrapped in a span with the class "typo3-docheader-pagePath"
32 * </output>
33 */
34 class PagePathViewHelper extends AbstractBackendViewHelper
35 {
36
37 /**
38 * This view helper renders HTML, thus output must not be escaped
39 *
40 * @var bool
41 */
42 protected $escapeOutput = false;
43
44 /**
45 * Renders the current page path
46 *
47 * @return string the rendered page path
48 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate::getPagePath() Note: can't call this method as it's protected!
49 */
50 public function render()
51 {
52 return static::renderStatic(
53 [],
54 $this->buildRenderChildrenClosure(),
55 $this->renderingContext
56 );
57 }
58
59 /**
60 * @param array $arguments
61 * @param \Closure $renderChildrenClosure
62 * @param RenderingContextInterface $renderingContext
63 *
64 * @return string
65 */
66 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
67 {
68 $id = GeneralUtility::_GP('id');
69 $pageRecord = BackendUtility::readPageAccess($id, $GLOBALS['BE_USER']->getPagePermsClause(1));
70 // Is this a real page
71 if ($pageRecord['uid']) {
72 $title = $pageRecord['_thePathFull'];
73 } else {
74 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
75 }
76 // Setting the path of the page
77 $pagePath = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.path')) . ': <span class="typo3-docheader-pagePath">';
78 // crop the title to title limit (or 50, if not defined)
79 $cropLength = empty($GLOBALS['BE_USER']->uc['titleLen']) ? 50 : $GLOBALS['BE_USER']->uc['titleLen'];
80 $croppedTitle = GeneralUtility::fixed_lgd_cs($title, -$cropLength);
81 if ($croppedTitle !== $title) {
82 $pagePath .= '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
83 } else {
84 $pagePath .= htmlspecialchars($title);
85 }
86 $pagePath .= '</span>';
87 return $pagePath;
88 }
89 }