‪TYPO3CMS  ‪main
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;
21 use TYPO3\CMS\Core\Imaging\IconSize;
28 
33 {
40  protected ‪$recordArray = [];
41 
42  protected ?‪ResourceInterface ‪$resource = null;
43 
44  public function ‪setResource(‪ResourceInterface ‪$resource): void
45  {
46  $this->resource = ‪$resource;
47  }
48 
54  public function ‪setRecordArray(array ‪$recordArray)
55  {
56  $this->recordArray = ‪$recordArray;
57  }
58 
64  public function ‪getPath()
65  {
66  $pageRecord = ‪$this->recordArray;
67  $title = '';
68  if ($this->resource) {
69  try {
70  $title = $this->resource->getStorage()->getName();
71  $title .= $this->resource->getParentFolder()->getReadablePath();
72  } catch (ResourceDoesNotExistException|InsufficientFolderAccessPermissionsException $e) {
73  }
74  } elseif (is_array($pageRecord) && !empty($pageRecord['uid'])) {
75  // Is this a real page
76  $title = substr($pageRecord['_thePathFull'] ?? '', 0, -1);
77  // Remove current page title
78  $pos = strrpos($title, $pageRecord['title']);
79  if ($pos !== false) {
80  $title = substr($title, 0, $pos);
81  }
82  }
83  // Setting the path of the page
84  // crop the title to title limit (or 50, if not defined)
85  $beUser = $this->‪getBackendUser();
86  $cropLength = empty($beUser->uc['titleLen']) ? 50 : (int)$beUser->uc['titleLen'];
87  $croppedTitle = ‪GeneralUtility::fixed_lgd_cs($title, -$cropLength);
88  if ($croppedTitle !== $title) {
89  $pagePath = '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
90  } else {
91  $pagePath = htmlspecialchars($title);
92  }
93  return $pagePath;
94  }
95 
101  public function ‪getRecordInformation()
102  {
103  $recordInformations = $this->‪getRecordInformations();
104  if (!empty($recordInformations)) {
105  $recordInformation = $recordInformations['icon'] .
106  ' <strong>' . htmlspecialchars($recordInformations['title']) . ($recordInformations['uid'] !== '' ? '&nbsp;[' . $recordInformations['uid'] . ']' : '') . '</strong>' .
107  (!empty($recordInformations['additionalInfo']) ? ' ' . htmlspecialchars($recordInformations['additionalInfo']) : '');
108  } else {
109  $recordInformation = '';
110  }
111  return $recordInformation;
112  }
113 
119  public function ‪getRecordInformationIcon()
120  {
121  $recordInformations = $this->‪getRecordInformations();
122  if (!empty($recordInformations)) {
123  $recordInformationIcon = $recordInformations['icon'];
124  } else {
125  $recordInformationIcon = null;
126  }
127  return $recordInformationIcon;
128  }
129 
135  public function ‪getRecordInformationTitle()
136  {
137  $recordInformations = $this->‪getRecordInformations();
138  if (!empty($recordInformations)) {
139  $title = $recordInformations['title'];
140  } else {
141  $title = '';
142  }
143 
144  // crop the title to title limit (or 50, if not defined)
145  $beUser = $this->‪getBackendUser();
146  $cropLength = empty($beUser->uc['titleLen']) ? 50 : (int)$beUser->uc['titleLen'];
147  return htmlspecialchars(‪GeneralUtility::fixed_lgd_cs($title, $cropLength));
148  }
149 
155  public function ‪getRecordInformationUid()
156  {
157  $recordInformations = $this->‪getRecordInformations();
158  if (!empty($recordInformations)) {
159  $recordInformationUid = $recordInformations['uid'];
160  } else {
161  $recordInformationUid = null;
162  }
163  return $recordInformationUid;
164  }
165 
171  public function ‪getRecordInformationAdditionalInfo(): string
172  {
173  $recordInformations = $this->‪getRecordInformations();
174  return $recordInformations['additionalInfo'] ?? '';
175  }
176 
177  public function ‪isFileOrFolder(): bool
178  {
179  return $this->resource !== null;
180  }
181 
187  protected function ‪getRecordInformations()
188  {
189  $pageRecord = ‪$this->recordArray;
190  if (empty($pageRecord) && $this->resource === null) {
191  return [];
192  }
193 
194  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
195  ‪$uid = '';
196  $title = '';
197  $additionalInfo = (!empty($pageRecord['_additional_info'] ?? '') ? $pageRecord['_additional_info'] : '');
198  // Add icon with context menu, etc:
199  // If the module is about a FAL resource
200  if ($this->resource) {
201  try {
202  $fileMountTitle = $this->resource->getStorage()->getFileMounts()[$this->resource->getIdentifier()]['title'] ?? '';
203  $title = $fileMountTitle ?: $this->resource->getName();
204  // If this is a folder but not in within file mount boundaries this is the root folder
205  if ($this->resource instanceof FolderInterface && !$this->resource->getStorage()->isWithinFileMountBoundaries($this->resource)) {
206  $theIcon = $iconFactory
207  ->getIconForResource(
208  $this->resource,
209  IconSize::SMALL,
210  null,
211  ['mount-root' => true]
212  )
213  ->setTitle($title)
214  ->render();
215  } else {
216  $theIcon = $iconFactory
217  ->getIconForResource(
218  $this->resource,
219  IconSize::SMALL
220  )
221  ->setTitle($title)
222  ->render();
223  }
224  $tableName = ($this->resource->getIdentifier() === $this->resource->getStorage()->getRootLevelFolder()->getIdentifier())
225  ? 'sys_filemounts' : 'sys_file';
226  if (method_exists($this->resource, 'getCombinedIdentifier')) {
227  $theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, $tableName, $this->resource->getCombinedIdentifier());
228  }
229  } catch (ResourceDoesNotExistException|InsufficientFolderAccessPermissionsException $e) {
230  $theIcon = '';
231  }
232  } elseif (is_array($pageRecord) && !empty($pageRecord['uid'])) {
233  // If there IS a real page
234  $theIcon = $iconFactory
235  ->getIconForRecord('pages', $pageRecord, IconSize::SMALL)
236  ->setTitle(BackendUtility::getRecordIconAltText($pageRecord, 'pages', false))
237  ->render();
238  // Make Icon:
239  $theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, 'pages', $pageRecord['uid']);
240  ‪$uid = $pageRecord['uid'];
241  $title = BackendUtility::getRecordTitle('pages', $pageRecord);
242  } else {
243  // On root-level of page tree
244  // Make Icon
245  $theIcon = $iconFactory
246  ->getIcon('apps-pagetree-root', IconSize::SMALL)
247  ->setTitle(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'])
248  ->render();
249  if ($this->‪getBackendUser()->isAdmin()) {
250  $theIcon = BackendUtility::wrapClickMenuOnIcon($theIcon, 'pages');
251  }
252  ‪$uid = '0';
253  $title = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
254  }
255  // returns array for icon, title, uid and additional info
256  return [
257  'uid' => ‪$uid,
258  'icon' => $theIcon,
259  'title' => $title,
260  'additionalInfo' => $additionalInfo,
261  ];
262  }
263 
264  protected function ‪getLanguageService(): ‪LanguageService
265  {
266  return ‪$GLOBALS['LANG'];
267  }
268 
269  protected function ‪getBackendUser(): ‪BackendUserAuthentication
270  {
271  return ‪$GLOBALS['BE_USER'];
272  }
273 }
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getLanguageService
‪getLanguageService()
Definition: MetaInformation.php:263
‪TYPO3\CMS\Core\Utility\GeneralUtility\fixed_lgd_cs
‪static string fixed_lgd_cs(string $string, int $chars, string $appendString='...')
Definition: GeneralUtility.php:92
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformations
‪array getRecordInformations()
Definition: MetaInformation.php:186
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\setResource
‪setResource(ResourceInterface $resource)
Definition: MetaInformation.php:43
‪TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException
Definition: InsufficientFolderAccessPermissionsException.php:23
‪TYPO3\CMS\Backend\Template\Components\MetaInformation
Definition: MetaInformation.php:33
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getPath
‪string getPath()
Definition: MetaInformation.php:63
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformationTitle
‪string getRecordInformationTitle()
Definition: MetaInformation.php:134
‪TYPO3\CMS\Core\Resource\ResourceInterface\getStorage
‪getStorage()
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\$resource
‪ResourceInterface $resource
Definition: MetaInformation.php:41
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformation
‪string getRecordInformation()
Definition: MetaInformation.php:100
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getBackendUser
‪getBackendUser()
Definition: MetaInformation.php:268
‪TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException
Definition: ResourceDoesNotExistException.php:23
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformationIcon
‪string getRecordInformationIcon()
Definition: MetaInformation.php:118
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformationAdditionalInfo
‪string getRecordInformationAdditionalInfo()
Definition: MetaInformation.php:170
‪TYPO3\CMS\Webhooks\Message\$uid
‪identifier readonly int $uid
Definition: PageModificationMessage.php:35
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Resource\FolderInterface
Definition: FolderInterface.php:24
‪TYPO3\CMS\Core\Resource\ResourceInterface
Definition: ResourceInterface.php:21
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Backend\Template\Components
Definition: AbstractControl.php:16
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\$recordArray
‪array $recordArray
Definition: MetaInformation.php:39
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\getRecordInformationUid
‪int null getRecordInformationUid()
Definition: MetaInformation.php:154
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\setRecordArray
‪setRecordArray(array $recordArray)
Definition: MetaInformation.php:53
‪TYPO3\CMS\Backend\Template\Components\MetaInformation\isFileOrFolder
‪isFileOrFolder()
Definition: MetaInformation.php:176