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