‪TYPO3CMS  10.4
PageLinkHandler.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 Psr\Http\Message\ServerRequestInterface;
31 
37 {
41  protected ‪$expandPage = 0;
42 
48  protected ‪$linkParts = [];
49 
59  public function ‪canHandleLink(array ‪$linkParts)
60  {
61  if (!‪$linkParts['url']) {
62  return false;
63  }
64  $data = ‪$linkParts['url'];
65  // Check if the page still exists
66  if ((int)$data['pageuid'] > 0) {
67  $pageRow = ‪BackendUtility::getRecordWSOL('pages', $data['pageuid']);
68  if (!$pageRow) {
69  return false;
70  }
71  } elseif ($data['pageuid'] !== 'current') {
72  return false;
73  }
74 
75  $this->linkParts = ‪$linkParts;
76  return true;
77  }
78 
84  public function ‪formatCurrentUrl()
85  {
86  $lang = $this->‪getLanguageService();
87  $titleLen = (int)$this->‪getBackendUser()->uc['titleLen'];
88 
89  $id = (int)$this->linkParts['url']['pageuid'];
90  $pageRow = ‪BackendUtility::getRecordWSOL('pages', $id);
91 
92  return $lang->getLL('page')
93  . ' \'' . GeneralUtility::fixed_lgd_cs($pageRow['title'], $titleLen) . '\''
94  . ' (ID: ' . $id . ($this->linkParts['url']['fragment'] ? ', #' . $this->linkParts['url']['fragment'] : '') . ')';
95  }
96 
104  public function ‪render(ServerRequestInterface $request)
105  {
106  GeneralUtility::makeInstance(PageRenderer::class)->loadRequireJsModule('TYPO3/CMS/Recordlist/PageLinkHandler');
107 
108  $this->expandPage = isset($request->getQueryParams()['expandPage']) ? (int)$request->getQueryParams()['expandPage'] : 0;
109  $this->‪setTemporaryDbMounts();
110 
111  $userTsConfig = $this->‪getBackendUser()->‪getTSConfig();
112 
113  $pageTree = GeneralUtility::makeInstance(ElementBrowserPageTreeView::class);
114  $pageTree->setLinkParameterProvider($this);
115  $pageTree->ext_showNavTitle = (bool)($userTsConfig['options.']['pageTree.']['showNavTitle'] ?? false);
116  $pageTree->ext_showPageId = (bool)($userTsConfig['options.']['pageTree.']['showPageIdWithTitle'] ?? false);
117  $pageTree->ext_showPathAboveMounts = (bool)($userTsConfig['options.']['pageTree.']['showPathAboveMounts'] ?? false);
118  $pageTree->addField('nav_title');
119 
120  $this->view->assign('temporaryTreeMountCancelLink', $this->‪getTemporaryTreeMountCancelNotice());
121  $this->view->assign('tree', $pageTree->getBrowsableTree());
122  $this->‪getRecordsOnExpandedPage($this->expandPage);
123  return $this->view->render('Page');
124  }
125 
131  protected function ‪getRecordsOnExpandedPage($pageId)
132  {
133  // If there is an anchor value (content element reference) in the element reference, then force an ID to expand:
134  if (!$pageId && isset($this->linkParts['url']['fragment'])) {
135  // Set to the current link page id.
136  $pageId = $this->linkParts['url']['pageuid'];
137  }
138  // Draw the record list IF there is a page id to expand:
139  if ($pageId && ‪MathUtility::canBeInterpretedAsInteger($pageId) && $this->‪getBackendUser()->isInWebMount($pageId)) {
140  $pageId = (int)$pageId;
141 
142  $activePageRecord = ‪BackendUtility::getRecordWSOL('pages', $pageId);
143  $this->view->assign('expandActivePage', true);
144 
145  // Create header for listing, showing the page title/icon
146  $this->view->assign('activePage', $activePageRecord);
147  $this->view->assign('activePageTitle', ‪BackendUtility::getRecordTitle('pages', $activePageRecord, true));
148  $this->view->assign('activePageIcon', $this->iconFactory->getIconForRecord('pages', $activePageRecord, ‪Icon::SIZE_SMALL)->render());
149 
150  // Look up tt_content elements from the expanded page
151  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
152  ->getQueryBuilderForTable('tt_content');
153 
154  $queryBuilder->getRestrictions()
155  ->removeAll()
156  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
157  ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->‪getBackendUser()->workspace));
158 
159  $contentElements = $queryBuilder
160  ->select('*')
161  ->from('tt_content')
162  ->where(
163  $queryBuilder->expr()->andX(
164  $queryBuilder->expr()->eq(
165  'pid',
166  $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)
167  ),
168  $queryBuilder->expr()->in(
169  'sys_language_uid',
170  $queryBuilder->createNamedParameter([$activePageRecord['sys_language_uid'], -1], Connection::PARAM_INT_ARRAY)
171  )
172  )
173  )
174  ->orderBy('colPos')
175  ->addOrderBy('sorting')
176  ->execute()
177  ->fetchAll();
178 
179  // Enrich list of records
180  foreach ($contentElements as &$contentElement) {
181  ‪BackendUtility::workspaceOL('tt_content', $contentElement);
182  $contentElement['url'] = GeneralUtility::makeInstance(LinkService::class)->asString(['type' => ‪LinkService::TYPE_PAGE, 'pageuid' => (int)$pageId, 'fragment' => $contentElement['uid']]);
183  $contentElement['isSelected'] = !empty($this->linkParts) && (int)$this->linkParts['url']['fragment'] === (int)$contentElement['uid'];
184  $contentElement['icon'] = $this->iconFactory->getIconForRecord('tt_content', $contentElement, ‪Icon::SIZE_SMALL)->render();
185  $contentElement['title'] = ‪BackendUtility::getRecordTitle('tt_content', $contentElement, true);
186  }
187  $this->view->assign('contentElements', $contentElements);
188  }
189  }
190 
196  protected function ‪getTemporaryTreeMountCancelNotice()
197  {
198  if ((int)$this->‪getBackendUser()->getSessionData('pageTree_temporaryMountPoint') > 0) {
199  return GeneralUtility::linkThisScript(['setTempDBmount' => 0]);
200  }
201  return '';
202  }
203 
207  public function ‪getBodyTagAttributes()
208  {
209  if (count($this->linkParts) === 0 || empty($this->linkParts['url']['pageuid'])) {
210  return [];
211  }
212  return [
213  'data-current-link' => GeneralUtility::makeInstance(LinkService::class)->asString([
214  'type' => ‪LinkService::TYPE_PAGE,
215  'pageuid' => (int)$this->linkParts['url']['pageuid'],
216  'fragment' => $this->linkParts['url']['fragment']
217  ])
218  ];
219  }
220 
226  public function ‪getUrlParameters(array $values)
227  {
228  $parameters = [
229  'expandPage' => isset($values['pid']) ? (int)$values['pid'] : $this->expandPage
230  ];
231  return array_merge($this->linkBrowser->getUrlParameters($values), $parameters);
232  }
233 
239  public function ‪isCurrentlySelectedItem(array $values)
240  {
241  return !empty($this->linkParts) && (int)$this->linkParts['url']['pageuid'] === (int)$values['pid'];
242  }
243 
249  public function ‪getScriptUrl()
250  {
251  return $this->linkBrowser->getScriptUrl();
252  }
253 
258  public function ‪modifyLinkAttributes(array $fieldDefinitions)
259  {
260  $configuration = $this->linkBrowser->getConfiguration();
261  // Depending where the configuration is set it can be 'pageIdSelector' (CKEditor yaml) or 'pageIdSelector.' (TSconfig)
262  if (!empty($configuration['pageIdSelector']['enabled']) || !empty($configuration['pageIdSelector.']['enabled'])) {
263  $this->linkAttributes[] = 'pageIdSelector';
264  $fieldDefinitions['pageIdSelector'] = '
265  <form class="form-horizontal"><div class="form-group form-group-sm">
266  <label class="col-xs-4 control-label">
267  ' . htmlspecialchars($this->‪getLanguageService()->getLL('page_id')) . '
268  </label>
269  <div class="col-xs-2">
270  <input type="number" size="6" name="luid" id="luid" class="form-control" />
271  </div>
272  <div class="col-xs-6">
273  <input class="btn btn-default t3js-pageLink" type="submit" value="' . htmlspecialchars($this->‪getLanguageService()->getLL('setLink')) . '" />
274  </div>
275  </div></form>';
276  }
277  return $fieldDefinitions;
278  }
279 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:74
‪TYPO3\CMS\Backend\Tree\View\ElementBrowserPageTreeView
Definition: ElementBrowserPageTreeView.php:30
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getTSConfig
‪array getTSConfig()
Definition: BackendUserAuthentication.php:1217
‪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\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordWSOL
‪static array getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
Definition: BackendUtility.php:139
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:36
‪TYPO3\CMS\Backend\Utility\BackendUtility\workspaceOL
‪static workspaceOL($table, &$row, $wsid=-99, $unsetMovePointers=false)
Definition: BackendUtility.php:3586
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction
Definition: WorkspaceRestriction.php:39