|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2020-2025 |
|
6
|
|
|
* @package MW |
|
7
|
|
|
* @subpackage View |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\Base\View\Helper\Url; |
|
12
|
|
|
|
|
13
|
|
|
use TYPO3\CMS\Core\Routing\RouterInterface; |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* View helper class for building URLs using the page router. |
|
18
|
|
|
* |
|
19
|
|
|
* @package MW |
|
20
|
|
|
* @subpackage View |
|
21
|
|
|
*/ |
|
22
|
|
|
class T3Router |
|
23
|
|
|
extends \Aimeos\Base\View\Helper\Url\Base |
|
24
|
|
|
implements \Aimeos\Base\View\Helper\Url\Iface |
|
25
|
|
|
{ |
|
26
|
|
|
private \TYPO3\CMS\Core\Routing\RouterInterface $router; |
|
27
|
|
|
private ?string $pageid; |
|
28
|
|
|
private array $fixed; |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Initializes the URL view helper. |
|
33
|
|
|
* |
|
34
|
|
|
* @param \Aimeos\Base\View\Iface $view View instance with registered view helpers |
|
35
|
|
|
* @param \TYPO3\CMS\Core\Routing\RouterInterface $router TYPO3 page router |
|
36
|
|
|
* @param array $fixed Fixed parameters that should be added to each URL |
|
37
|
|
|
* @param string|null $pageid ID of the current page as default value |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct( \Aimeos\Base\View\Iface $view, \TYPO3\CMS\Core\Routing\RouterInterface $router, |
|
40
|
|
|
array $fixed, ?string $pageid = null ) |
|
41
|
|
|
{ |
|
42
|
|
|
parent::__construct( $view ); |
|
43
|
|
|
|
|
44
|
|
|
$this->router = clone $router; |
|
45
|
|
|
$this->pageid = $pageid; |
|
46
|
|
|
$this->fixed = $fixed; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Returns the URL assembled from the given arguments. |
|
52
|
|
|
* |
|
53
|
|
|
* @param string|null $target Route or page which should be the target of the link (if any) |
|
54
|
|
|
* @param string|null $controller Name of the controller which should be part of the link (if any) |
|
55
|
|
|
* @param string|null $action Name of the action which should be part of the link (if any) |
|
56
|
|
|
* @param array $params Associative list of parameters that should be part of the URL |
|
57
|
|
|
* @param array $trailing Trailing URL parts that are not relevant to identify the resource (for pretty URLs) |
|
58
|
|
|
* @param array $config Additional configuration parameter per URL |
|
59
|
|
|
* @return string Complete URL that can be used in the template |
|
60
|
|
|
*/ |
|
61
|
|
|
public function transform( ?string $target = null, ?string $controller = null, ?string $action = null, |
|
62
|
|
|
array $params = [], array $trailing = [], array $config = [] ) : string |
|
63
|
|
|
{ |
|
64
|
|
|
$params['controller'] = $controller !== null ? ucfirst( $controller ) : null; |
|
65
|
|
|
$params['action'] = $action; |
|
66
|
|
|
|
|
67
|
|
|
if( $params['locale'] ?? null ) { |
|
68
|
|
|
$params['L'] = $params['locale']; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$abs = !empty( $config['absoluteUri'] ) ? RouterInterface::ABSOLUTE_URL : RouterInterface::ABSOLUTE_PATH; |
|
72
|
|
|
|
|
73
|
|
|
return (string) $this->router->generateUri( $target ?: $this->pageid, ['ai' => $params] + $this->fixed, join( '/', $trailing ), $abs ); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|