9
9
10
10
use eZ \Publish \API \Repository \ContentService ;
11
11
use eZ \Publish \API \Repository \LocationService ;
12
- use eZ \Publish \API \Repository \URLAliasService ;
13
12
use eZ \Publish \API \Repository \Values \Content \Content ;
14
13
use eZ \Publish \API \Repository \Values \Content \ContentStruct ;
15
14
use eZ \Publish \API \Repository \Values \Content \Location ;
21
20
use EzSystems \RepositoryForms \Event \RepositoryFormEvents ;
22
21
use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
23
22
use Symfony \Component \HttpFoundation \RedirectResponse ;
23
+ use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
24
24
use Symfony \Component \Routing \RouterInterface ;
25
25
26
26
/**
@@ -37,9 +37,6 @@ class ContentFormProcessor implements EventSubscriberInterface
37
37
/** @var \Symfony\Component\Routing\RouterInterface */
38
38
private $ router ;
39
39
40
- /** @var \eZ\Publish\API\Repository\URLAliasService */
41
- private $ urlAliasService ;
42
-
43
40
/**
44
41
* @param \eZ\Publish\API\Repository\ContentService $contentService
45
42
* @param \eZ\Publish\API\Repository\LocationService $locationService
@@ -49,13 +46,11 @@ class ContentFormProcessor implements EventSubscriberInterface
49
46
public function __construct (
50
47
ContentService $ contentService ,
51
48
LocationService $ locationService ,
52
- RouterInterface $ router ,
53
- URLAliasService $ urlAliasService
49
+ RouterInterface $ router
54
50
) {
55
51
$ this ->contentService = $ contentService ;
56
52
$ this ->locationService = $ locationService ;
57
53
$ this ->router = $ router ;
58
- $ this ->urlAliasService = $ urlAliasService ;
59
54
}
60
55
61
56
/**
@@ -110,7 +105,6 @@ public function processSaveDraft(FormActionEvent $event)
110
105
* @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
111
106
* @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException
112
107
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
113
- * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
114
108
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
115
109
* @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
116
110
*/
@@ -123,35 +117,19 @@ public function processPublish(FormActionEvent $event)
123
117
$ draft = $ this ->saveDraft ($ data , $ form ->getConfig ()->getOption ('languageCode ' ));
124
118
$ content = $ this ->contentService ->publishVersion ($ draft ->versionInfo );
125
119
126
- $ location = $ this ->locationService ->loadLocation ($ content ->contentInfo ->mainLocationId );
120
+ $ redirectUrl = $ form ['redirectUrlAfterPublish ' ]->getData () ?: $ this ->router ->generate (
121
+ '_ezpublishLocation ' , [
122
+ 'locationId ' => $ content ->contentInfo ->mainLocationId ,
123
+ ]
124
+ );
127
125
128
- $ redirectUrl = $ form ['redirectUrlAfterPublish ' ]->getData () ?: $ this ->getSystemUrl ($ location , [$ content ->versionInfo ->initialLanguageCode ]);
129
126
$ event ->setResponse (new RedirectResponse ($ redirectUrl ));
130
127
}
131
128
132
- /**
133
- * @param \eZ\Publish\API\Repository\Values\Content\Location $location
134
- * @param array $prioritizedLanguageList
135
- *
136
- * @return string
137
- *
138
- * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
139
- */
140
- private function getSystemUrl (Location $ location , array $ prioritizedLanguageList ): string
141
- {
142
- return $ this ->urlAliasService ->reverseLookup (
143
- $ location ,
144
- null ,
145
- true ,
146
- $ prioritizedLanguageList
147
- )->path ;
148
- }
149
-
150
129
/**
151
130
* @param \EzSystems\RepositoryForms\Event\FormActionEvent $event
152
131
*
153
132
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException
154
- * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
155
133
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
156
134
*/
157
135
public function processCancel (FormActionEvent $ event )
@@ -160,14 +138,10 @@ public function processCancel(FormActionEvent $event)
160
138
$ data = $ event ->getData ();
161
139
162
140
if ($ data ->isNew ()) {
163
- $ parentLocation = $ this ->locationService ->loadLocation (
164
- $ data ->getLocationStructs ()[0 ]->parentLocationId
165
- );
166
- $ url = $ this ->getSystemUrl (
167
- $ parentLocation ,
168
- [$ data ->mainLanguageCode , $ parentLocation ->contentInfo ->mainLanguageCode ]
169
- );
170
- $ response = new RedirectResponse ($ url );
141
+ $ response = new RedirectResponse ($ this ->router ->generate (
142
+ '_ezpublishLocation ' ,
143
+ ['locationId ' => $ data ->getLocationStructs ()[0 ]->parentLocationId ]
144
+ ));
171
145
$ event ->setResponse ($ response );
172
146
173
147
return ;
@@ -187,11 +161,10 @@ public function processCancel(FormActionEvent $event)
187
161
$ this ->contentService ->deleteVersion ($ versionInfo );
188
162
}
189
163
190
- $ locationToRedirect = $ this ->locationService ->loadLocation ($ redirectionLocationId );
191
-
192
- $ url = $ this ->getSystemUrl (
193
- $ locationToRedirect ,
194
- [$ locationToRedirect ->contentInfo ->mainLanguageCode ]
164
+ $ url = $ this ->router ->generate (
165
+ '_ezpublishLocation ' ,
166
+ ['locationId ' => $ redirectionLocationId ],
167
+ UrlGeneratorInterface::ABSOLUTE_URL
195
168
);
196
169
197
170
$ event ->setResponse (new RedirectResponse ($ url ));
0 commit comments