2 namespace TYPO3\CMS\Backend\Template\Components
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Backend\Utility\BackendUtility
;
18 use TYPO3\CMS\Core\Imaging\Icon
;
19 use TYPO3\CMS\Core\Imaging\IconFactory
;
20 use TYPO3\CMS\Core\Localization\LanguageService
;
21 use TYPO3\CMS\Core\
Resource\Exception\InsufficientFolderAccessPermissionsException
;
22 use TYPO3\CMS\Core\
Resource\Exception\ResourceDoesNotExistException
;
23 use TYPO3\CMS\Core\
Resource\FolderInterface
;
24 use TYPO3\CMS\Core\
Resource\ResourceFactory
;
25 use TYPO3\CMS\Core\Utility\GeneralUtility
;
34 * Typically this is a page record
38 protected $recordArray = [];
43 * @param array $recordArray RecordArray
45 public function setRecordArray(array $recordArray)
47 $this->recordArray
= $recordArray;
51 * Generate the page path for docHeader
53 * @return string The page path
55 public function getPath()
57 $pageRecord = $this->recordArray
;
59 // Is this a real page
60 if (is_array($pageRecord) && $pageRecord['uid']) {
61 $title = substr($pageRecord['_thePathFull'], 0, -1);
62 // Remove current page title
63 $pos = strrpos($title, $pageRecord['title']);
65 $title = substr($title, 0, $pos);
67 } elseif (!empty($pageRecord['combined_identifier'])) {
69 $resourceObject = ResourceFactory
::getInstance()->getInstance()->getObjectFromCombinedIdentifier($pageRecord['combined_identifier']);
70 $title = $resourceObject->getStorage()->getName() . ':';
71 $title .= $resourceObject->getParentFolder()->getReadablePath();
72 } catch (ResourceDoesNotExistException
$e) {
73 } catch (InsufficientFolderAccessPermissionsException
$e) {
76 // Setting the path of the page
77 // crop the title to title limit (or 50, if not defined)
78 $beUser = $this->getBackendUser();
79 $cropLength = empty($beUser->uc
['titleLen']) ?
50 : $beUser->uc
['titleLen'];
80 $croppedTitle = GeneralUtility
::fixed_lgd_cs($title, -$cropLength);
81 if ($croppedTitle !== $title) {
82 $pagePath = '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
84 $pagePath = htmlspecialchars($title);
90 * Setting page icon with context menu + uid for docheader
92 * @return string Record info
94 public function getRecordInformation()
96 $recordInformations = $this->getRecordInformations();
97 if (!empty($recordInformations)) {
98 $recordInformation = $recordInformations['icon'] .
99 ' <strong>' . htmlspecialchars($recordInformations['title']) . ($recordInformations['uid'] !== '' ?
' [' . $recordInformations['uid'] . ']' : '') . '</strong>' .
100 (!empty($recordInformations['additionalInfo']) ?
' ' . htmlspecialchars($recordInformations['additionalInfo']) : '');
102 $recordInformation = '';
104 return $recordInformation;
110 * @return string Record icon
112 public function getRecordInformationIcon()
114 $recordInformations = $this->getRecordInformations();
115 if (!empty($recordInformations)) {
116 $recordInformationIcon = $recordInformations['icon'];
118 $recordInformationIcon = null;
120 return $recordInformationIcon;
126 * @return string Record title, already htmlspecialchar()'ed
128 public function getRecordInformationTitle()
130 $recordInformations = $this->getRecordInformations();
131 if (!empty($recordInformations)) {
132 $title = $recordInformations['title'];
137 // crop the title to title limit (or 50, if not defined)
138 $beUser = $this->getBackendUser();
139 $cropLength = empty($beUser->uc
['titleLen']) ?
50 : $beUser->uc
['titleLen'];
140 return htmlspecialchars(GeneralUtility
::fixed_lgd_cs($title, $cropLength));
146 * @return null|int Record uid
148 public function getRecordInformationUid()
150 $recordInformations = $this->getRecordInformations();
151 if (!empty($recordInformations)) {
152 $recordInformationUid = $recordInformations['uid'];
154 $recordInformationUid = null;
156 return $recordInformationUid;
162 * @return array Record info
164 protected function getRecordInformations()
166 $pageRecord = $this->recordArray
;
167 if (empty($pageRecord)) {
171 $iconFactory = GeneralUtility
::makeInstance(IconFactory
::class);
174 $additionalInfo = (!empty($pageRecord['_additional_info']) ?
$pageRecord['_additional_info'] : '');
175 // Add icon with context menu, etc:
176 // If there IS a real page
177 if (is_array($pageRecord) && $pageRecord['uid']) {
178 $toolTip = BackendUtility
::getRecordToolTip($pageRecord, 'pages');
179 $iconImg = '<span ' . $toolTip . '>' . $iconFactory->getIconForRecord('pages', $pageRecord, Icon
::SIZE_SMALL
)->render() . '</span>';
181 $theIcon = BackendUtility
::wrapClickMenuOnIcon($iconImg, 'pages', $pageRecord['uid']);
182 $uid = $pageRecord['uid'];
183 $title = BackendUtility
::getRecordTitle('pages', $pageRecord);
184 } elseif (is_array($pageRecord) && !empty($pageRecord['combined_identifier'])) {
185 // If the module is about a FAL resource
187 $resourceObject = ResourceFactory
::getInstance()->getInstance()->getObjectFromCombinedIdentifier($pageRecord['combined_identifier']);
188 $fileMountTitle = $resourceObject->getStorage()->getFileMounts()[$resourceObject->getIdentifier()]['title'];
189 $title = $fileMountTitle ?
: $resourceObject->getName();
190 // If this is a folder but not in within file mount boundaries this is the root folder
191 if ($resourceObject instanceof FolderInterface
&& !$resourceObject->getStorage()->isWithinFileMountBoundaries($resourceObject)) {
192 $iconImg = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForResource(
196 ['mount-root' => true]
197 )->render() . '</span>';
199 $iconImg = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForResource(
202 )->render() . '</span>';
204 $theIcon = BackendUtility
::wrapClickMenuOnIcon($iconImg, 'sys_file', $pageRecord['combined_identifier']);
205 } catch (ResourceDoesNotExistException
$e) {
209 // On root-level of page tree
211 $iconImg = '<span title="' .
212 htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) .
214 $iconFactory->getIcon('apps-pagetree-root', Icon
::SIZE_SMALL
)->render() . '</span>';
215 if ($this->getBackendUser()->isAdmin()) {
216 $theIcon = BackendUtility
::wrapClickMenuOnIcon($iconImg, 'pages');
221 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
223 // returns array for icon, title, uid and additional info
228 'additionalInfo' => $additionalInfo
233 * Get LanguageService Object
235 * @return LanguageService
237 protected function getLanguageService()
239 return $GLOBALS['LANG'];
243 * Get the Backend User Object
245 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
247 protected function getBackendUser()
249 return $GLOBALS['BE_USER'];