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