‪TYPO3CMS  11.5
MetaInformation.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
27 
32 {
39  protected ‪$recordArray = [];
40 
41  protected ?‪ResourceInterface ‪$resource = null;
42 
43  public function ‪setResource(‪ResourceInterface ‪$resource): void
44  {
45  $this->resource = ‪$resource;
46  }
47 
53  public function ‪setRecordArray(array ‪$recordArray)
54  {
55  $this->recordArray = ‪$recordArray;
56  }
57 
63  public function ‪getPath()
64  {
65  $pageRecord = ‪$this->recordArray;
66  $title = '';
67  if ($this->resource) {
68  try {
69  $title = $this->resource->getStorage()->getName();
70  $title .= $this->resource->getParentFolder()->getReadablePath();
71  } catch (ResourceDoesNotExistException|InsufficientFolderAccessPermissionsException $e) {
72  }
73  } elseif (is_array($pageRecord) && !empty($pageRecord['uid'])) {
74  // Is this a real page
75  $title = substr($pageRecord['_thePathFull'] ?? '', 0, -1);
76  // Remove current page title
77  $pos = strrpos($title, $pageRecord['title']);
78  if ($pos !== false) {
79  $title = substr($title, 0, $pos);
80  }
81  }
82  // Setting the path of the page
83  // crop the title to title limit (or 50, if not defined)
84  $beUser = $this->‪getBackendUser();
85  $cropLength = empty($beUser->uc['titleLen']) ? 50 : (int)$beUser->uc['titleLen'];
86  $croppedTitle = GeneralUtility::fixed_lgd_cs($title, -$cropLength);
87  if ($croppedTitle !== $title) {
88  $pagePath = '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
89  } else {
90  $pagePath = htmlspecialchars($title);
91  }
92  return $pagePath;
93  }
94 
100  public function ‪getRecordInformation()
101  {
102  $recordInformations = $this->‪getRecordInformations();
103  if (!empty($recordInformations)) {
104  $recordInformation = $recordInformations['icon'] .
105  ' <strong>' . htmlspecialchars($recordInformations['title']) . ($recordInformations['uid'] !== '' ? '&nbsp;[' . $recordInformations['uid'] . ']' : '') . '</strong>' .
106  (!empty($recordInformations['additionalInfo']) ? ' ' . htmlspecialchars($recordInformations['additionalInfo']) : '');
107  } else {
108  $recordInformation = '';
109  }
110  return $recordInformation;
111  }
112 
118  public function ‪getRecordInformationIcon()
119  {
120  $recordInformations = $this->‪getRecordInformations();
121  if (!empty($recordInformations)) {
122  $recordInformationIcon = $recordInformations['icon'];
123  } else {
124  $recordInformationIcon = null;
125  }
126  return $recordInformationIcon;
127  }
128 
134  public function ‪getRecordInformationTitle()
135  {
136  $recordInformations = $this->‪getRecordInformations();
137  if (!empty($recordInformations)) {
138  $title = $recordInformations['title'];
139  } else {
140  $title = '';
141  }
142 
143  // crop the title to title limit (or 50, if not defined)
144  $beUser = $this->‪getBackendUser();
145  $cropLength = empty($beUser->uc['titleLen']) ? 50 : $beUser->uc['titleLen'];
146  return htmlspecialchars(GeneralUtility::fixed_lgd_cs($title, $cropLength));
147  }
148 
154  public function ‪getRecordInformationUid()
155  {
156  $recordInformations = $this->‪getRecordInformations();
157  if (!empty($recordInformations)) {
158  $recordInformationUid = $recordInformations['uid'];
159  } else {
160  $recordInformationUid = null;
161  }
162  return $recordInformationUid;
163  }
164 
170  public function ‪getRecordInformationAdditionalInfo(): string
171  {
172  $recordInformations = $this->‪getRecordInformations();
173  return $recordInformations['additionalInfo'] ?? '';
174  }
175 
176  public function ‪isFileOrFolder(): bool
177  {
178  return $this->resource !== null;
179  }
180 
186  protected function ‪getRecordInformations()
187  {
188  $pageRecord = ‪$this->recordArray;
189  if (empty($pageRecord) && $this->resource === null) {
190  return [];
191  }
192 
193  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
194  $uid = '';
195  $title = '';
196  $additionalInfo = (!empty($pageRecord['_additional_info'] ?? '') ? $pageRecord['_additional_info'] : '');
197  // Add icon with context menu, etc:
198  // If the module is about a FAL resource
199  if ($this->resource) {
200  try {
201  $fileMountTitle = $this->resource->getStorage()->getFileMounts()[$this->resource->getIdentifier()]['title'] ?? '';
202  $title = $fileMountTitle ?: $this->resource->getName();
203  // If this is a folder but not in within file mount boundaries this is the root folder
204  if ($this->resource instanceof FolderInterface && !$this->resource->getStorage()->isWithinFileMountBoundaries($this->resource)) {
205  $theIcon = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForResource(
206  $this->resource,
208  null,
209  ['mount-root' => true]
210  )->render() . '</span>';
211  } else {
212  $theIcon = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForResource(
213  $this->resource,
215  )->render() . '</span>';
216  }
217  $tableName = ($this->resource->getIdentifier() === $this->resource->getStorage()->getRootLevelFolder()->getIdentifier())
218  ? 'sys_filemounts' : 'sys_file';
219  if (method_exists($this->resource, 'getCombinedIdentifier')) {
220  $theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, $tableName, $this->resource->getCombinedIdentifier());
221  }
222  } catch (ResourceDoesNotExistException|InsufficientFolderAccessPermissionsException $e) {
223  $theIcon = '';
224  }
225  } elseif (is_array($pageRecord) && !empty($pageRecord['uid'])) {
226  // If there IS a real page
227  $toolTip = BackendUtility::getRecordToolTip($pageRecord, 'pages');
228  $theIcon = '<span ' . $toolTip . '>' . $iconFactory->getIconForRecord('pages', $pageRecord, ‪Icon::SIZE_SMALL)->render() . '</span>';
229  // Make Icon:
230  $theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, 'pages', $pageRecord['uid']);
231  $uid = $pageRecord['uid'];
232  $title = BackendUtility::getRecordTitle('pages', $pageRecord);
233  } else {
234  // On root-level of page tree
235  // Make Icon
236  $theIcon = '<span title="' .
237  htmlspecialchars(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) .
238  '">' .
239  $iconFactory->getIcon('apps-pagetree-root', ‪Icon::SIZE_SMALL)->render() . '</span>';
240  if ($this->‪getBackendUser()->isAdmin()) {
241  $theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, 'pages');
242  }
243  $uid = '0';
244  $title = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
245  }
246  // returns array for icon, title, uid and additional info
247  return [
248  'uid' => $uid,
249  'icon' => $theIcon,
250  'title' => $title,
251  'additionalInfo' => $additionalInfo,
252  ];
253  }
254 
260  protected function ‪getLanguageService()
261  {
262  return ‪$GLOBALS['LANG'];
263  }
264 
270  protected function ‪getBackendUser()
271  {
272  return ‪$GLOBALS['BE_USER'];
273  }
274 }
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getLanguageService
‪LanguageService getLanguageService()
Definition: MetaInformation.php:259
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformations
‪array getRecordInformations()
Definition: MetaInformation.php:185
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\setResource
‪setResource(ResourceInterface $resource)
Definition: MetaInformation.php:42
‪TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException
Definition: InsufficientFolderAccessPermissionsException.php:23
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Backend\Template\Components\MetaInformation
Definition: MetaInformation.php:32
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getPath
‪string getPath()
Definition: MetaInformation.php:62
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformationTitle
‪string getRecordInformationTitle()
Definition: MetaInformation.php:133
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\$resource
‪ResourceInterface $resource
Definition: MetaInformation.php:40
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Core\Resource\ResourceInterface\getStorage
‪ResourceStorage getStorage()
‪TYPO3\CMS\Core\Resource\ResourceStorage\isWithinFileMountBoundaries
‪bool isWithinFileMountBoundaries($subject, $checkWriteAccess=false)
Definition: ResourceStorage.php:611
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformation
‪string getRecordInformation()
Definition: MetaInformation.php:99
‪TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException
Definition: ResourceDoesNotExistException.php:23
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformationIcon
‪string getRecordInformationIcon()
Definition: MetaInformation.php:117
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformationAdditionalInfo
‪string getRecordInformationAdditionalInfo()
Definition: MetaInformation.php:169
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Resource\FolderInterface
Definition: FolderInterface.php:22
‪TYPO3\CMS\Core\Resource\ResourceInterface
Definition: ResourceInterface.php:22
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Backend\Template\Components
Definition: AbstractControl.php:16
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\$recordArray
‪array $recordArray
Definition: MetaInformation.php:38
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getBackendUser
‪TYPO3 CMS Core Authentication BackendUserAuthentication getBackendUser()
Definition: MetaInformation.php:269
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformationUid
‪int null getRecordInformationUid()
Definition: MetaInformation.php:153
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\setRecordArray
‪setRecordArray(array $recordArray)
Definition: MetaInformation.php:52
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\isFileOrFolder
‪isFileOrFolder()
Definition: MetaInformation.php:175