[BUGFIX] Use late static binding for compilable viewhelpers
[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 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\Utility\BackendUtility;
25 use TYPO3\CMS\Core\Utility\GeneralUtility;
26 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
27 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
28
29 /**
30 * View helper which returns the current page path as known from TYPO3 backend modules
31 * Note: This view helper is experimental!
32 *
33 * = Examples =
34 *
35 * <code>
36 * <f:be.pagePath />
37 * </code>
38 * <output>
39 * Current page path, prefixed with "Path:" and wrapped in a span with the class "typo3-docheader-pagePath"
40 * </output>
41 */
42 class PagePathViewHelper extends AbstractBackendViewHelper implements CompilableInterface {
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 return static::renderStatic(
52 array(),
53 $this->buildRenderChildrenClosure(),
54 $this->renderingContext
55 );
56 }
57
58 /**
59 * @param array $arguments
60 * @param callable $renderChildrenClosure
61 * @param RenderingContextInterface $renderingContext
62 *
63 * @return string
64 */
65 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
66 $id = GeneralUtility::_GP('id');
67 $pageRecord = BackendUtility::readPageAccess($id, $GLOBALS['BE_USER']->getPagePermsClause(1));
68 // Is this a real page
69 if ($pageRecord['uid']) {
70 $title = $pageRecord['_thePathFull'];
71 } else {
72 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
73 }
74 // Setting the path of the page
75 $pagePath = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.path', TRUE) . ': <span class="typo3-docheader-pagePath">';
76 // crop the title to title limit (or 50, if not defined)
77 $cropLength = empty($GLOBALS['BE_USER']->uc['titleLen']) ? 50 : $GLOBALS['BE_USER']->uc['titleLen'];
78 $croppedTitle = GeneralUtility::fixed_lgd_cs($title, -$cropLength);
79 if ($croppedTitle !== $title) {
80 $pagePath .= '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
81 } else {
82 $pagePath .= htmlspecialchars($title);
83 }
84 $pagePath .= '</span>';
85 return $pagePath;
86 }
87
88 }