1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace eZ\Publish\Core\Event; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\SPI\Repository\Decorator\URLAliasServiceDecorator; |
12
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
13
|
|
|
use eZ\Publish\API\Repository\URLAliasService as URLAliasServiceInterface; |
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location; |
15
|
|
|
use eZ\Publish\Core\Event\URLAlias\BeforeCreateGlobalUrlAliasEvent; |
16
|
|
|
use eZ\Publish\Core\Event\URLAlias\BeforeCreateUrlAliasEvent; |
17
|
|
|
use eZ\Publish\Core\Event\URLAlias\BeforeRefreshSystemUrlAliasesForLocationEvent; |
18
|
|
|
use eZ\Publish\Core\Event\URLAlias\BeforeRemoveAliasesEvent; |
19
|
|
|
use eZ\Publish\Core\Event\URLAlias\CreateGlobalUrlAliasEvent; |
20
|
|
|
use eZ\Publish\Core\Event\URLAlias\CreateUrlAliasEvent; |
21
|
|
|
use eZ\Publish\Core\Event\URLAlias\RefreshSystemUrlAliasesForLocationEvent; |
22
|
|
|
use eZ\Publish\Core\Event\URLAlias\RemoveAliasesEvent; |
23
|
|
|
use eZ\Publish\Core\Event\URLAlias\URLAliasEvents; |
24
|
|
|
|
25
|
|
|
class URLAliasService extends URLAliasServiceDecorator implements URLAliasServiceInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface |
29
|
|
|
*/ |
30
|
|
|
protected $eventDispatcher; |
31
|
|
|
|
32
|
|
|
public function __construct( |
33
|
|
|
URLAliasServiceInterface $innerService, |
34
|
|
|
EventDispatcherInterface $eventDispatcher |
35
|
|
|
) { |
36
|
|
|
parent::__construct($innerService); |
37
|
|
|
|
38
|
|
|
$this->eventDispatcher = $eventDispatcher; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function createUrlAlias( |
42
|
|
|
Location $location, |
43
|
|
|
$path, |
44
|
|
|
$languageCode, |
45
|
|
|
$forwarding = false, |
46
|
|
|
$alwaysAvailable = false |
47
|
|
|
) { |
48
|
|
|
$eventData = [ |
49
|
|
|
$location, |
50
|
|
|
$path, |
51
|
|
|
$languageCode, |
52
|
|
|
$forwarding, |
53
|
|
|
$alwaysAvailable, |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
$beforeEvent = new BeforeCreateUrlAliasEvent(...$eventData); |
|
|
|
|
57
|
|
View Code Duplication |
if ($this->eventDispatcher->dispatch(URLAliasEvents::BEFORE_CREATE_URL_ALIAS, $beforeEvent)->isPropagationStopped()) { |
|
|
|
|
58
|
|
|
return $beforeEvent->getReturnValue(); |
59
|
|
|
} else { |
60
|
|
|
$urlAlias = parent::createUrlAlias($location, $path, $languageCode, $forwarding, $alwaysAvailable); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$this->eventDispatcher->dispatch( |
64
|
|
|
URLAliasEvents::CREATE_URL_ALIAS, |
65
|
|
|
new CreateUrlAliasEvent($urlAlias, ...$eventData) |
|
|
|
|
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
return $urlAlias; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function createGlobalUrlAlias( |
72
|
|
|
$resource, |
73
|
|
|
$path, |
74
|
|
|
$languageCode, |
75
|
|
|
$forwarding = false, |
76
|
|
|
$alwaysAvailable = false |
77
|
|
|
) { |
78
|
|
|
$eventData = [ |
79
|
|
|
$resource, |
80
|
|
|
$path, |
81
|
|
|
$languageCode, |
82
|
|
|
$forwarding, |
83
|
|
|
$alwaysAvailable, |
84
|
|
|
]; |
85
|
|
|
|
86
|
|
|
$beforeEvent = new BeforeCreateGlobalUrlAliasEvent(...$eventData); |
|
|
|
|
87
|
|
View Code Duplication |
if ($this->eventDispatcher->dispatch(URLAliasEvents::BEFORE_CREATE_GLOBAL_URL_ALIAS, $beforeEvent)->isPropagationStopped()) { |
|
|
|
|
88
|
|
|
return $beforeEvent->getReturnValue(); |
89
|
|
|
} else { |
90
|
|
|
$urlAlias = parent::createGlobalUrlAlias($resource, $path, $languageCode, $forwarding, $alwaysAvailable); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$this->eventDispatcher->dispatch( |
94
|
|
|
URLAliasEvents::CREATE_GLOBAL_URL_ALIAS, |
95
|
|
|
new CreateGlobalUrlAliasEvent($urlAlias, ...$eventData) |
|
|
|
|
96
|
|
|
); |
97
|
|
|
|
98
|
|
|
return $urlAlias; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function removeAliases(array $aliasList) |
102
|
|
|
{ |
103
|
|
|
$eventData = [$aliasList]; |
104
|
|
|
|
105
|
|
|
$beforeEvent = new BeforeRemoveAliasesEvent(...$eventData); |
106
|
|
|
if ($this->eventDispatcher->dispatch(URLAliasEvents::BEFORE_REMOVE_ALIASES, $beforeEvent)->isPropagationStopped()) { |
107
|
|
|
return; |
108
|
|
|
} else { |
109
|
|
|
parent::removeAliases($aliasList); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$this->eventDispatcher->dispatch( |
113
|
|
|
URLAliasEvents::REMOVE_ALIASES, |
114
|
|
|
new RemoveAliasesEvent(...$eventData) |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function refreshSystemUrlAliasesForLocation(Location $location): void |
119
|
|
|
{ |
120
|
|
|
$eventData = [$location]; |
121
|
|
|
|
122
|
|
|
$beforeEvent = new BeforeRefreshSystemUrlAliasesForLocationEvent(...$eventData); |
123
|
|
|
if ($this->eventDispatcher->dispatch(URLAliasEvents::BEFORE_REFRESH_SYSTEM_URL_ALIASES_FOR_LOCATION, $beforeEvent)->isPropagationStopped()) { |
124
|
|
|
return; |
125
|
|
|
} else { |
126
|
|
|
parent::refreshSystemUrlAliasesForLocation($location); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
$this->eventDispatcher->dispatch( |
130
|
|
|
URLAliasEvents::REFRESH_SYSTEM_URL_ALIASES_FOR_LOCATION, |
131
|
|
|
new RefreshSystemUrlAliasesForLocationEvent(...$eventData) |
132
|
|
|
); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|