‪TYPO3CMS  11.5
RecordLinkHandler.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ServerRequestInterface;
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
27 
33 {
39  protected ‪$identifier;
40 
46  protected ‪$configuration = [];
47 
53  protected ‪$linkParts = [];
54 
58  protected ‪$expandPage = 0;
59 
68  {
69  parent::initialize(‪$linkBrowser, ‪$identifier, ‪$configuration);
70  $this->identifier = ‪$identifier;
71  $this->configuration = ‪$configuration;
72  }
73 
82  public function ‪canHandleLink(array ‪$linkParts): bool
83  {
84  if (!‪$linkParts['url'] || !isset(‪$linkParts['url']['identifier']) || ‪$linkParts['url']['identifier'] !== $this->identifier) {
85  return false;
86  }
87 
88  $data = ‪$linkParts['url'];
89 
90  // Get the related record
91  $table = $this->configuration['table'];
92  $record = BackendUtility::getRecord($table, $data['uid']);
93  if ($record === null) {
94  ‪$linkParts['title'] = $this->‪getLanguageService()->‪getLL('recordNotFound');
95  } else {
96  $linkParts['pid'] = (int)$record['pid'];
97  ‪$linkParts['title'] = !empty(‪$linkParts['title']) ? ‪$linkParts['title'] : BackendUtility::getRecordTitle($table, $record);
98  }
99  ‪$linkParts['tableName'] = $this->‪getLanguageService()->‪sL(‪$GLOBALS['TCA'][$table]['ctrl']['title']);
100  ‪$linkParts['url']['type'] = ‪$linkParts['type'];
101  $this->linkParts = ‪$linkParts;
102 
103  return true;
104  }
105 
111  public function ‪formatCurrentUrl(): string
112  {
113  return sprintf(
114  '%s: %s [uid: %d]',
115  $this->linkParts['tableName'],
116  $this->linkParts['title'],
117  $this->linkParts['url']['uid']
118  );
119  }
120 
127  public function ‪render(ServerRequestInterface $request): string
128  {
129  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Recordlist/RecordLinkHandler');
130  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Recordlist/RecordSearch');
131  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Viewport/ResizableNavigation');
132  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ColumnSelectorButton');
133  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tree/PageBrowser');
135 
136  // Define the current page
137  if (isset($request->getQueryParams()['expandPage'])) {
138  $this->expandPage = (int)$request->getQueryParams()['expandPage'];
139  } elseif (isset($this->configuration['storagePid'])) {
140  $this->expandPage = (int)$this->configuration['storagePid'];
141  } elseif (isset($this->linkParts['pid'])) {
142  $this->expandPage = (int)$this->linkParts['pid'];
143  }
144 
145  $databaseBrowser = GeneralUtility::makeInstance(RecordBrowser::class);
146  $recordList = $databaseBrowser->displayRecordsForPage(
147  $this->expandPage,
148  $this->configuration['table'],
149  $this->‪getUrlParameters([])
150  );
151 
152  $this->view->assignMultiple([
153  'treeEnabled' => (bool)($this->configuration['hidePageTree'] ?? false) === false,
154  'pageTreeMountPoints' => ‪GeneralUtility::intExplode(',', $this->configuration['pageTreeMountPoints'] ?? '', true),
155  'recordList' => $recordList,
156  'initialNavigationWidth' => $this->‪getBackendUser()->uc['selector']['navigation']['width'] ?? 250,
157  'treeActions' => ['link'],
158  ]);
159 
160  $this->view->setTemplate('Record');
161  return '';
162  }
163 
169  public function ‪getBodyTagAttributes(): array
170  {
171  $attributes = [
172  'data-identifier' => 't3://record?identifier=' . $this->identifier . '&uid=',
173  ];
174  if (!empty($this->linkParts)) {
175  $attributes['data-current-link'] = GeneralUtility::makeInstance(LinkService::class)->asString($this->linkParts['url']);
176  }
177 
178  return $attributes;
179  }
180 
187  public function ‪getUrlParameters(array $values): array
188  {
189  $pid = isset($values['pid']) ? (int)$values['pid'] : $this->expandPage;
190  $parameters = [
191  'expandPage' => $pid,
192  ];
193 
194  return array_merge(
195  $this->linkBrowser->getUrlParameters($values),
196  ['P' => $this->linkBrowser->getParameters()],
197  $parameters
198  );
199  }
200 
207  public function ‪isCurrentlySelectedItem(array $values): bool
208  {
209  return !empty($this->linkParts) && (int)$this->linkParts['pid'] === (int)$values['pid'];
210  }
211 
217  public function ‪getScriptUrl(): string
218  {
219  return $this->linkBrowser->getScriptUrl();
220  }
221 }
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:161
‪TYPO3\CMS\Recordlist\Browser\RecordBrowser
Definition: RecordBrowser.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility\intExplode
‪static int[] intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:927
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\initializeWebmountsForElementBrowser
‪initializeWebmountsForElementBrowser()
Definition: BackendUserAuthentication.php:1046
‪TYPO3\CMS\Core\Localization\LanguageService\getLL
‪string getLL($index)
Definition: LanguageService.php:121
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50