-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathContentEditController.php
106 lines (92 loc) · 3.43 KB
/
ContentEditController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformAdminUiBundle\Controller;
use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\LocationService;
use EzSystems\EzPlatformAdminUi\Event\ContentProxyTranslateEvent;
use EzSystems\EzPlatformAdminUi\View\ContentTranslateSuccessView;
use EzSystems\EzPlatformAdminUi\View\ContentTranslateView;
use Ibexa\AdminUi\Event\CancelEditVersionDraftEvent;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
class ContentEditController extends Controller
{
/** @var \eZ\Publish\API\Repository\ContentService */
private $contentService;
/** @var \eZ\Publish\API\Repository\LocationService */
private $locationService;
/** @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface */
private $eventDispatcher;
public function __construct(
ContentService $contentService,
LocationService $locationService,
EventDispatcherInterface $eventDispatcher
) {
$this->contentService = $contentService;
$this->locationService = $locationService;
$this->eventDispatcher = $eventDispatcher;
}
public function proxyTranslateAction(
int $contentId,
?string $fromLanguageCode,
string $toLanguageCode,
?int $locationId = null
): Response {
/** @var \EzSystems\EzPlatformAdminUi\Event\ContentProxyTranslateEvent $event */
$event = $this->eventDispatcher->dispatch(
new ContentProxyTranslateEvent(
$contentId,
$fromLanguageCode,
$toLanguageCode,
null,
$locationId
)
);
if ($event->hasResponse()) {
return $event->getResponse();
}
// Fallback to "translate"
return $this->redirectToRoute('ezplatform.content.translate', [
'contentId' => $contentId,
'fromLanguageCode' => $fromLanguageCode,
'toLanguageCode' => $toLanguageCode,
]);
}
/**
* @param \EzSystems\EzPlatformAdminUi\View\ContentTranslateView $view
*
* @return \EzSystems\EzPlatformAdminUi\View\ContentTranslateView
*/
public function translateAction(ContentTranslateView $view): ContentTranslateView
{
return $view;
}
/**
* @param \EzSystems\EzPlatformAdminUi\View\ContentTranslateSuccessView $view
*
* @return \EzSystems\EzPlatformAdminUi\View\ContentTranslateSuccessView
*/
public function translationSuccessAction(ContentTranslateSuccessView $view): ContentTranslateSuccessView
{
return $view;
}
public function cancelEditVersionDraftAction(
int $contentId,
int $versionNo,
int $referrerLocationId,
string $languageCode
): Response {
$content = $this->contentService->loadContent($contentId, [$languageCode], $versionNo);
$referrerlocation = $this->locationService->loadLocation($referrerLocationId);
$response = $this->eventDispatcher->dispatch(
new CancelEditVersionDraftEvent(
$content,
$referrerlocation
)
)->getResponse();
return $response ?? $this->redirectToLocation($referrerlocation);
}
}