‪TYPO3CMS  9.5
MetaInformation.php
Go to the documentation of this file.
1 <?php
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 
26 
31 {
38  protected ‪$recordArray = [];
39 
45  public function ‪setRecordArray(array ‪$recordArray)
46  {
47  $this->recordArray = ‪$recordArray;
48  }
49 
55  public function ‪getPath()
56  {
57  $pageRecord = ‪$this->recordArray;
58  $title = '';
59  // Is this a real page
60  if (is_array($pageRecord) && !empty($pageRecord['uid'])) {
61  $title = substr($pageRecord['_thePathFull'], 0, -1);
62  // Remove current page title
63  $pos = strrpos($title, $pageRecord['title']);
64  if ($pos !== false) {
65  $title = substr($title, 0, $pos);
66  }
67  } elseif (!empty($pageRecord['combined_identifier'])) {
68  try {
69  $resourceObject = ‪ResourceFactory::getInstance()->‪getObjectFromCombinedIdentifier($pageRecord['combined_identifier']);
70  $title = $resourceObject->‪getStorage()->‪getName() . ':';
71  $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 : $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 = ‪ResourceFactory::getInstance()->‪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:29
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformations
‪array getRecordInformations()
Definition: MetaInformation.php:174
‪TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException
Definition: InsufficientFolderAccessPermissionsException.php:21
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Backend\Template\Components\MetaInformation
Definition: MetaInformation.php:31
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getPath
‪string getPath()
Definition: MetaInformation.php:54
‪TYPO3\CMS\Core\Resource\ResourceFactory\getObjectFromCombinedIdentifier
‪FileInterface Folder getObjectFromCombinedIdentifier($identifier)
Definition: ResourceFactory.php:582
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformationTitle
‪string getRecordInformationTitle()
Definition: MetaInformation.php:127
‪TYPO3\CMS\Core\Resource\ResourceFactory\getInstance
‪static ResourceFactory getInstance()
Definition: ResourceFactory.php:39
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:31
‪TYPO3\CMS\Core\Resource\ResourceInterface\getStorage
‪ResourceStorage getStorage()
‪TYPO3\CMS\Core\Resource\ResourceStorage\isWithinFileMountBoundaries
‪bool isWithinFileMountBoundaries($subject, $checkWriteAccess=false)
Definition: ResourceStorage.php:536
‪TYPO3\CMS\Backend\Utility\BackendUtility\wrapClickMenuOnIcon
‪static string wrapClickMenuOnIcon( $content, $table, $uid=0, $context='', $_addParams='', $_enDisItems='', $returnTagParameters=false)
Definition: BackendUtility.php:2759
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformation
‪string getRecordInformation()
Definition: MetaInformation.php:93
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException
Definition: ResourceDoesNotExistException.php:21
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordToolTip
‪static string getRecordToolTip(array $row, $table='pages')
Definition: BackendUtility.php:1603
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordTitle
‪static string getRecordTitle($table, $row, $prep=false, $forceResult=true)
Definition: BackendUtility.php:1811
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformationIcon
‪string getRecordInformationIcon()
Definition: MetaInformation.php:111
‪TYPO3\CMS\Core\Resource\ResourceStorage\getFileMounts
‪array getFileMounts()
Definition: ResourceStorage.php:523
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformationAdditionalInfo
‪string getRecordInformationAdditionalInfo()
Definition: MetaInformation.php:163
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Resource\FolderInterface
Definition: FolderInterface.php:21
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Backend\Template\Components
Definition: AbstractControl.php:2
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\$recordArray
‪array $recordArray
Definition: MetaInformation.php:37
‪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:45
‪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:44
‪TYPO3\CMS\Core\Resource\ResourceStorage\getName
‪string getName()
Definition: ResourceStorage.php:261