TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
core/Classes/LinkHandling/PageLinkHandler.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Core\LinkHandling;
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 
22 {
23 
28  protected $baseUrn = 't3://page';
29 
36  public function asString(array $parameters): string
37  {
38  $urn = $this->baseUrn;
39  if (isset($parameters['pagealias']) && $parameters['pagealias'] !== 'current') {
40  $urn .= '?alias=' . $parameters['pagealias'];
41  } else {
42  $urn .= '?uid=' . $parameters['pageuid'];
43  }
44  $urn = rtrim($urn, ':');
45  if (!empty($parameters['pagetype'])) {
46  $urn .= '&type=' . $parameters['pagetype'];
47  }
48  if (!empty($parameters['parameters'])) {
49  $urn .= '&' . ltrim($parameters['parameters'], '?&');
50  }
51  if (!empty($parameters['fragment'])) {
52  $urn .= '#' . $parameters['fragment'];
53  }
54 
55  return $urn;
56  }
57 
64  public function resolveHandlerData(array $data): array
65  {
66  $result = [];
67  if (isset($data['uid'])) {
68  $result['pageuid'] = $data['uid'];
69  unset($data['uid']);
70  }
71  if (isset($data['alias'])) {
72  $result['pagealias'] = $data['alias'];
73  unset($data['alias']);
74  }
75  if (isset($data['type'])) {
76  $result['pagetype'] = $data['type'];
77  unset($data['type']);
78  }
79  if (!empty($data)) {
80  $result['parameters'] = http_build_query($data);
81  }
82  if (empty($result)) {
83  $result['pageuid'] = 'current';
84  }
85 
86  return $result;
87  }
88 }