‪TYPO3CMS  10.4
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;
30 
36 {
42  protected ‪$identifier;
43 
49  protected ‪$configuration = [];
50 
56  protected ‪$linkParts = [];
57 
61  protected ‪$expandPage = 0;
62 
71  {
72  parent::initialize(‪$linkBrowser, ‪$identifier, ‪$configuration);
73  $this->identifier = ‪$identifier;
74  $this->configuration = ‪$configuration;
75  }
76 
85  public function ‪canHandleLink(array ‪$linkParts): bool
86  {
87  if (!‪$linkParts['url'] || !isset(‪$linkParts['url']['identifier']) || ‪$linkParts['url']['identifier'] !== $this->identifier) {
88  return false;
89  }
90 
91  $data = ‪$linkParts['url'];
92 
93  // Get the related record
94  $table = $this->configuration['table'];
95  $record = ‪BackendUtility::getRecord($table, $data['uid']);
96  if ($record === null) {
97  ‪$linkParts['title'] = $this->‪getLanguageService()->‪getLL('recordNotFound');
98  } else {
99  $linkParts['tableName'] = $this->‪getLanguageService()->‪sL(‪$GLOBALS['TCA'][$table]['ctrl']['title']);
100  ‪$linkParts['pid'] = (int)$record['pid'];
101  ‪$linkParts['title'] = ‪$linkParts['title'] ?: ‪BackendUtility::getRecordTitle($table, $record);
102  }
103  ‪$linkParts['url']['type'] = ‪$linkParts['type'];
104  $this->linkParts = ‪$linkParts;
105 
106  return true;
107  }
108 
114  public function ‪formatCurrentUrl(): string
115  {
116  return sprintf(
117  '%s: %s [uid: %d]',
118  $this->linkParts['tableName'],
119  $this->linkParts['title'],
120  $this->linkParts['url']['uid']
121  );
122  }
123 
130  public function ‪render(ServerRequestInterface $request): string
131  {
132  // Declare JS module
133  GeneralUtility::makeInstance(PageRenderer::class)->loadRequireJsModule('TYPO3/CMS/Recordlist/RecordLinkHandler');
134 
135  // Define the current page
136  if (isset($request->getQueryParams()['expandPage'])) {
137  $this->expandPage = (int)$request->getQueryParams()['expandPage'];
138  } elseif (isset($this->configuration['storagePid'])) {
139  $this->expandPage = (int)$this->configuration['storagePid'];
140  } elseif (isset($this->linkParts['pid'])) {
141  $this->expandPage = (int)$this->linkParts['pid'];
142  }
143  $this->‪setTemporaryDbMounts();
144 
145  $databaseBrowser = GeneralUtility::makeInstance(RecordBrowser::class);
146 
147  $recordList = $databaseBrowser->displayRecordsForPage(
148  $this->expandPage,
149  $this->configuration['table'],
150  $this->‪getUrlParameters([])
151  );
152 
153  $path = GeneralUtility::getFileAbsFileName('EXT:recordlist/Resources/Private/Templates/LinkBrowser/Record.html');
154  ‪$view = GeneralUtility::makeInstance(StandaloneView::class);
157  'tree' => $this->configuration['hidePageTree'] ? '' : $this->‪renderPageTree(),
158  'recordList' => $recordList,
159  ]);
160 
161  return ‪$view->‪render();
162  }
163 
169  protected function ‪renderPageTree(): string
170  {
171  $userTsConfig = $this->‪getBackendUser()->‪getTSConfig();
172 
174  $pageTree = GeneralUtility::makeInstance(RecordBrowserPageTreeView::class);
175  $pageTree->setLinkParameterProvider($this);
176  $pageTree->ext_showPageId = (bool)($userTsConfig['options.']['pageTree.']['showPageIdWithTitle'] ?? false);
177  $pageTree->ext_showNavTitle = (bool)($userTsConfig['options.']['pageTree.']['showNavTitle'] ?? false);
178  $pageTree->ext_showPathAboveMounts = (bool)($userTsConfig['options.']['pageTree.']['showPathAboveMounts'] ?? false);
179  $pageTree->addField('nav_title');
180 
181  // Load the mount points, if any
182  // NOTE: mount points actually override the page tree
183  if (!empty($this->configuration['pageTreeMountPoints'])) {
184  $pageTree->MOUNTS = ‪GeneralUtility::intExplode(',', $this->configuration['pageTreeMountPoints'], true);
185  }
186 
187  return $pageTree->getBrowsableTree();
188  }
189 
195  public function ‪getBodyTagAttributes(): array
196  {
197  $attributes = [
198  'data-identifier' => 't3://record?identifier=' . $this->identifier . '&uid=',
199  ];
200  if (!empty($this->linkParts)) {
201  $attributes['data-current-link'] = GeneralUtility::makeInstance(LinkService::class)->asString($this->linkParts['url']);
202  }
203 
204  return $attributes;
205  }
206 
213  public function ‪getUrlParameters(array $values): array
214  {
215  $pid = isset($values['pid']) ? (int)$values['pid'] : $this->expandPage;
216  $parameters = [
217  'expandPage' => $pid,
218  ];
219 
220  return array_merge(
221  $this->linkBrowser->getUrlParameters($values),
222  ['P' => $this->linkBrowser->getParameters()],
223  $parameters
224  );
225  }
226 
233  public function ‪isCurrentlySelectedItem(array $values): bool
234  {
235  return !empty($this->linkParts) && (int)$this->linkParts['pid'] === (int)$values['pid'];
236  }
237 
243  public function ‪getScriptUrl(): string
244  {
245  return $this->linkBrowser->getScriptUrl();
246  }
247 }
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getTSConfig
‪array getTSConfig()
Definition: BackendUserAuthentication.php:1217
‪TYPO3\CMS\Recordlist\Tree\View\RecordBrowserPageTreeView
Definition: RecordBrowserPageTreeView.php:28
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:194
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:42
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordTitle
‪static string getRecordTitle($table, $row, $prep=false, $forceResult=true)
Definition: BackendUtility.php:1541
‪TYPO3\CMS\Recordlist\Browser\RecordBrowser
Definition: RecordBrowser.php:28
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setTemplatePathAndFilename
‪setTemplatePathAndFilename($templatePathAndFilename)
Definition: AbstractTemplateView.php:103
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:95
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility\intExplode
‪static int[] intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:988
‪TYPO3\CMS\Extbase\Mvc\View\ViewInterface\render
‪string render()
‪TYPO3\CMS\Core\Localization\LanguageService\getLL
‪string getLL($index)
Definition: LanguageService.php:154
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Extbase\Mvc\View\ViewInterface\assignMultiple
‪TYPO3 CMS Extbase Mvc View ViewInterface assignMultiple(array $values)