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