[BUGFIX] Use non-deprecated API calls in MetaInformation
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Template / Components / MetaInformation.php
1 <?php
2 namespace TYPO3\CMS\Backend\Template\Components;
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\Core\Resource\Exception\ResourceDoesNotExistException;
18 use TYPO3\CMS\Core\Resource\Folder;
19 use TYPO3\CMS\Core\Resource\FolderInterface;
20 use TYPO3\CMS\Core\Resource\ResourceFactory;
21 use TYPO3\CMS\Backend\Template\ModuleTemplate;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Backend\Utility\IconUtility;
24 use TYPO3\CMS\Core\Imaging\Icon;
25 use TYPO3\CMS\Core\Utility\GeneralUtility;
26 use TYPO3\CMS\Lang\LanguageService;
27 use TYPO3\CMS\Core\Imaging\IconFactory;
28
29 /**
30 * MetaInformation
31 */
32 class MetaInformation
33 {
34
35 /**
36 * The recordArray.
37 * Typically this is a page record
38 *
39 * @var array
40 */
41 protected $recordArray = [];
42
43 /**
44 * Set the RecordArray
45 *
46 * @param array $recordArray RecordArray
47 *
48 * @return void
49 */
50 public function setRecordArray(array $recordArray)
51 {
52 $this->recordArray = $recordArray;
53 }
54
55 /**
56 * Generate the page path for docHeader
57 *
58 * @return string The page path
59 */
60 public function getPath()
61 {
62 $pageRecord = $this->recordArray;
63 $title = '';
64 // Is this a real page
65 if (is_array($pageRecord) && $pageRecord['uid']) {
66 $title = substr($pageRecord['_thePathFull'], 0, -1);
67 // Remove current page title
68 $pos = strrpos($title, $pageRecord['title']);
69 if ($pos !== false) {
70 $title = substr($title, 0, $pos);
71 }
72 } elseif (!empty($pageRecord['combined_identifier'])) {
73 try {
74 $resourceObject = ResourceFactory::getInstance()->getInstance()->getObjectFromCombinedIdentifier($pageRecord['combined_identifier']);
75 $title = $resourceObject->getStorage()->getName() . ':';
76 $title .= $resourceObject->getParentFolder()->getReadablePath();
77 } catch (ResourceDoesNotExistException $e) {}
78 }
79 // Setting the path of the page
80 // crop the title to title limit (or 50, if not defined)
81 $beUser = $this->getBackendUser();
82 $cropLength = empty($beUser->uc['titleLen']) ? 50 : $beUser->uc['titleLen'];
83 $croppedTitle = GeneralUtility::fixed_lgd_cs($title, -$cropLength);
84 if ($croppedTitle !== $title) {
85 $pagePath = '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
86 } else {
87 $pagePath = htmlspecialchars($title);
88 }
89 return $pagePath;
90 }
91
92 /**
93 * Setting page icon with clickMenu + uid for docheader
94 *
95 * @return string Record info
96 */
97 public function getRecordInformation()
98 {
99 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
100 $moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
101 $pageRecord = $this->recordArray;
102 $uid = '';
103 $additionalInfo = (!empty($pageRecord['_additional_info']) ? $pageRecord['_additional_info'] : '');
104 // Add icon with clickMenu, etc:
105 // If there IS a real page
106 if (is_array($pageRecord) && $pageRecord['uid']) {
107 $altText = BackendUtility::getRecordIconAltText($pageRecord, 'pages');
108 $iconImg = '<span title="' . $altText . '">' . $iconFactory->getIconForRecord('pages', $pageRecord, Icon::SIZE_SMALL)->render() . '</span>';
109 // Make Icon:
110 $theIcon = $moduleTemplate->wrapClickMenuOnIcon($iconImg, 'pages', $pageRecord['uid']);
111 $uid = $pageRecord['uid'];
112 $title = BackendUtility::getRecordTitle('pages', $pageRecord);
113 // If the module is about a FAL resource
114 } elseif (is_array($pageRecord) && !empty($pageRecord['combined_identifier'])) {
115 try {
116 $resourceObject = ResourceFactory::getInstance()->getInstance()->getObjectFromCombinedIdentifier($pageRecord['combined_identifier']);
117 $title = $resourceObject->getName();
118 // If this is a folder but not in within file mount boundaries this is the root folder
119 if ($resourceObject instanceof FolderInterface && !$resourceObject->getStorage()->isWithinFileMountBoundaries($resourceObject)) {
120 $iconImg = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForResource(
121 $resourceObject,
122 Icon::SIZE_SMALL,
123 null,
124 array('mount-root' => true)
125 )->render() . '</span>';
126 } else {
127 $iconImg = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForResource(
128 $resourceObject,
129 Icon::SIZE_SMALL
130 )->render() . '</span>';
131 }
132 $theIcon = $moduleTemplate->wrapClickMenuOnIcon($iconImg, $pageRecord['combined_identifier']);
133 } catch (ResourceDoesNotExistException $e) {
134 $theIcon = '';
135 }
136 } else {
137 // On root-level of page tree
138 // Make Icon
139 $iconImg = '<span title="' .
140 htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) .
141 '">' .
142 $iconFactory->getIcon('apps-pagetree-root', Icon::SIZE_SMALL)->render() . '</span>';
143 if ($this->getBackendUser()->isAdmin()) {
144 $theIcon = $moduleTemplate->wrapClickMenuOnIcon($iconImg, 'pages', 0);
145 } else {
146 $theIcon = $iconImg;
147 }
148 $uid = '0';
149 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
150 }
151 // Setting icon with clickMenu + uid
152 return $theIcon .
153 ' <strong>' . htmlspecialchars($title) . ($uid !== '' ? '&nbsp;[' . $uid . ']' : '') . '</strong>' .
154 (!empty($additionalInfo) ? ' ' . htmlspecialchars($additionalInfo) : '');
155 }
156
157 /**
158 * Get LanguageService Object
159 *
160 * @return LanguageService
161 */
162 protected function getLanguageService()
163 {
164 return $GLOBALS['LANG'];
165 }
166
167 /**
168 * Get the Backend User Object
169 *
170 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
171 */
172 protected function getBackendUser()
173 {
174 return $GLOBALS['BE_USER'];
175 }
176 }