‪TYPO3CMS  10.4
PageLinkHandler.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 
24 {
25 
30  protected ‪$baseUrn = 't3://page';
31 
38  public function ‪asString(array $parameters): string
39  {
40  $urn = $this->baseUrn . '?uid=' . $parameters['pageuid'];
41  $urn = rtrim($urn, ':');
42  // Page type is set and not empty (= "0" in this case means it is not empty)
43  if (isset($parameters['pagetype']) && strlen((string)$parameters['pagetype']) > 0) {
44  $urn .= '&type=' . $parameters['pagetype'];
45  }
46  if (!empty($parameters['parameters'])) {
47  $urn .= '&' . ltrim($parameters['parameters'], '?&');
48  }
49  if (!empty($parameters['fragment'])) {
50  $urn .= '#' . $parameters['fragment'];
51  }
52 
53  return $urn;
54  }
55 
62  public function ‪resolveHandlerData(array $data): array
63  {
64  $result = [];
65  if (isset($data['uid'])) {
66  $result['pageuid'] = $data['uid'];
67  unset($data['uid']);
68  }
69  if (isset($data['type'])) {
70  $result['pagetype'] = $data['type'];
71  unset($data['type']);
72  }
73  if (!empty($data)) {
74  $result['parameters'] = http_build_query($data, '', '&', PHP_QUERY_RFC3986);
75  }
76  if (empty($result)) {
77  $result['pageuid'] = 'current';
78  }
79 
80  return $result;
81  }
82 }