‪TYPO3CMS  10.4
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 
27 
32 {
39  protected ‪$recordArray = [];
40 
46  public function ‪setRecordArray(array ‪$recordArray)
47  {
48  $this->recordArray = ‪$recordArray;
49  }
50 
56  public function ‪getPath()
57  {
58  $pageRecord = ‪$this->recordArray;
59  $title = '';
60  // Is this a real page
61  if (is_array($pageRecord) && !empty($pageRecord['uid'])) {
62  $title = substr($pageRecord['_thePathFull'], 0, -1);
63  // Remove current page title
64  $pos = strrpos($title, $pageRecord['title']);
65  if ($pos !== false) {
66  $title = substr($title, 0, $pos);
67  }
68  } elseif (!empty($pageRecord['combined_identifier'])) {
69  try {
70  $resourceObject = GeneralUtility::makeInstance(ResourceFactory::class)->getObjectFromCombinedIdentifier($pageRecord['combined_identifier']);
71  $title = $resourceObject->getStorage()->getName() . ':';
72  $title .= $resourceObject->getParentFolder()->getReadablePath();
74  }
75  }
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 : (int)$beUser->uc['titleLen'];
80  $croppedTitle = GeneralUtility::fixed_lgd_cs($title, -$cropLength);
81  if ($croppedTitle !== $title) {
82  $pagePath = '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
83  } else {
84  $pagePath = htmlspecialchars($title);
85  }
86  return $pagePath;
87  }
88 
94  public function ‪getRecordInformation()
95  {
96  $recordInformations = $this->‪getRecordInformations();
97  if (!empty($recordInformations)) {
98  $recordInformation = $recordInformations['icon'] .
99  ' <strong>' . htmlspecialchars($recordInformations['title']) . ($recordInformations['uid'] !== '' ? '&nbsp;[' . $recordInformations['uid'] . ']' : '') . '</strong>' .
100  (!empty($recordInformations['additionalInfo']) ? ' ' . htmlspecialchars($recordInformations['additionalInfo']) : '');
101  } else {
102  $recordInformation = '';
103  }
104  return $recordInformation;
105  }
106 
112  public function ‪getRecordInformationIcon()
113  {
114  $recordInformations = $this->‪getRecordInformations();
115  if (!empty($recordInformations)) {
116  $recordInformationIcon = $recordInformations['icon'];
117  } else {
118  $recordInformationIcon = null;
119  }
120  return $recordInformationIcon;
121  }
122 
128  public function ‪getRecordInformationTitle()
129  {
130  $recordInformations = $this->‪getRecordInformations();
131  if (!empty($recordInformations)) {
132  $title = $recordInformations['title'];
133  } else {
134  $title = '';
135  }
136 
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));
141  }
142 
148  public function ‪getRecordInformationUid()
149  {
150  $recordInformations = $this->‪getRecordInformations();
151  if (!empty($recordInformations)) {
152  $recordInformationUid = $recordInformations['uid'];
153  } else {
154  $recordInformationUid = null;
155  }
156  return $recordInformationUid;
157  }
158 
164  public function ‪getRecordInformationAdditionalInfo(): string
165  {
166  $recordInformations = $this->‪getRecordInformations();
167  return $recordInformations['additionalInfo'] ?? '';
168  }
169 
175  protected function ‪getRecordInformations()
176  {
177  $pageRecord = ‪$this->recordArray;
178  if (empty($pageRecord)) {
179  return [];
180  }
181 
182  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
183  $uid = '';
184  $title = '';
185  $additionalInfo = (!empty($pageRecord['_additional_info']) ? $pageRecord['_additional_info'] : '');
186  // Add icon with context menu, etc:
187  // If there IS a real page
188  if (is_array($pageRecord) && !empty($pageRecord['uid'])) {
189  $toolTip = ‪BackendUtility::getRecordToolTip($pageRecord, 'pages');
190  $iconImg = '<span ' . $toolTip . '>' . $iconFactory->getIconForRecord('pages', $pageRecord, ‪Icon::SIZE_SMALL)->render() . '</span>';
191  // Make Icon:
192  $theIcon = ‪BackendUtility::wrapClickMenuOnIcon($iconImg, 'pages', $pageRecord['uid']);
193  $uid = $pageRecord['uid'];
194  $title = ‪BackendUtility::getRecordTitle('pages', $pageRecord);
195  } elseif (is_array($pageRecord) && !empty($pageRecord['combined_identifier'])) {
196  // If the module is about a FAL resource
197  try {
198  $resourceObject = GeneralUtility::makeInstance(ResourceFactory::class)->getObjectFromCombinedIdentifier($pageRecord['combined_identifier']);
199  $fileMountTitle = $resourceObject->getStorage()->getFileMounts()[$resourceObject->getIdentifier()]['title'] ?? '';
200  $title = $fileMountTitle ?: $resourceObject->getName();
201  // If this is a folder but not in within file mount boundaries this is the root folder
202  if ($resourceObject instanceof ‪FolderInterface && !$resourceObject->‪getStorage()->‪isWithinFileMountBoundaries($resourceObject)) {
203  $iconImg = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForResource(
204  $resourceObject,
206  null,
207  ['mount-root' => true]
208  )->render() . '</span>';
209  } else {
210  $iconImg = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForResource(
211  $resourceObject,
213  )->render() . '</span>';
214  }
215  $tableName = ($resourceObject->getIdentifier() === $resourceObject->getStorage()->getRootLevelFolder()->getIdentifier())
216  ? 'sys_filemounts' : 'sys_file';
217  $theIcon = ‪BackendUtility::wrapClickMenuOnIcon($iconImg, $tableName, $pageRecord['combined_identifier']);
218  } catch (‪ResourceDoesNotExistException $e) {
219  $theIcon = '';
220  }
221  } else {
222  // On root-level of page tree
223  // Make Icon
224  $iconImg = '<span title="' .
225  htmlspecialchars(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) .
226  '">' .
227  $iconFactory->getIcon('apps-pagetree-root', ‪Icon::SIZE_SMALL)->render() . '</span>';
228  if ($this->‪getBackendUser()->isAdmin()) {
229  $theIcon = ‪BackendUtility::wrapClickMenuOnIcon($iconImg, 'pages');
230  } else {
231  $theIcon = $iconImg;
232  }
233  $uid = '0';
234  $title = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
235  }
236  // returns array for icon, title, uid and additional info
237  return [
238  'uid' => $uid,
239  'icon' => $theIcon,
240  'title' => $title,
241  'additionalInfo' => $additionalInfo
242  ];
243  }
244 
250  protected function ‪getLanguageService()
251  {
252  return ‪$GLOBALS['LANG'];
253  }
254 
260  protected function ‪getBackendUser()
261  {
262  return ‪$GLOBALS['BE_USER'];
263  }
264 }
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getLanguageService
‪LanguageService getLanguageService()
Definition: MetaInformation.php:249
‪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:174
‪TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException
Definition: InsufficientFolderAccessPermissionsException.php:24
‪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:55
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformationTitle
‪string getRecordInformationTitle()
Definition: MetaInformation.php:127
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪TYPO3\CMS\Core\Resource\ResourceInterface\getStorage
‪ResourceStorage getStorage()
‪TYPO3\CMS\Core\Resource\ResourceStorage\isWithinFileMountBoundaries
‪bool isWithinFileMountBoundaries($subject, $checkWriteAccess=false)
Definition: ResourceStorage.php:589
‪TYPO3\CMS\Backend\Utility\BackendUtility\wrapClickMenuOnIcon
‪static string wrapClickMenuOnIcon( $content, $table, $uid=0, $context='', $_addParams='', $_enDisItems='', $returnTagParameters=false)
Definition: BackendUtility.php:2510
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformation
‪string getRecordInformation()
Definition: MetaInformation.php:93
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException
Definition: ResourceDoesNotExistException.php:24
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordToolTip
‪static string getRecordToolTip(array $row, $table='pages')
Definition: BackendUtility.php:1339
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordTitle
‪static string getRecordTitle($table, $row, $prep=false, $forceResult=true)
Definition: BackendUtility.php:1541
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformationIcon
‪string getRecordInformationIcon()
Definition: MetaInformation.php:111
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformationAdditionalInfo
‪string getRecordInformationAdditionalInfo()
Definition: MetaInformation.php:163
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Resource\FolderInterface
Definition: FolderInterface.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:259
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformationUid
‪int null getRecordInformationUid()
Definition: MetaInformation.php:147
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\setRecordArray
‪setRecordArray(array $recordArray)
Definition: MetaInformation.php:45