From 429f9553041ec53144dfc2a9f6c49ce5435a5921 Mon Sep 17 00:00:00 2001 From: Slawomir Dolzycki-Uchto Date: Tue, 31 Aug 2021 17:30:18 +0200 Subject: [PATCH] IBX-431: Allowed interception of canceling the draft version edit (#1876) * IBX-431: Allowed interception of canceling the draft version edit * fix: Readability * fix: Code review --- .../Controller/ContentEditController.php | 32 +++++++++++ src/bundle/Resources/config/routing.yaml | 5 ++ .../themes/admin/content/edit/edit.html.twig | 23 +++++++- src/lib/Event/CancelEditVersionDraftEvent.php | 54 +++++++++++++++++++ 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 src/lib/Event/CancelEditVersionDraftEvent.php diff --git a/src/bundle/Controller/ContentEditController.php b/src/bundle/Controller/ContentEditController.php index 37ce6e6ec5..c54c2b6c56 100644 --- a/src/bundle/Controller/ContentEditController.php +++ b/src/bundle/Controller/ContentEditController.php @@ -6,20 +6,33 @@ */ 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; } @@ -68,4 +81,23 @@ public function translationSuccessAction(ContentTranslateSuccessView $view): Con { 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); + } } diff --git a/src/bundle/Resources/config/routing.yaml b/src/bundle/Resources/config/routing.yaml index a5e1aaa97e..60a1920e6d 100644 --- a/src/bundle/Resources/config/routing.yaml +++ b/src/bundle/Resources/config/routing.yaml @@ -587,6 +587,11 @@ ezplatform.content.draft.edit: options: expose: true +ibexa.content.draft.edit.cancel: + path: /content/edit/draft/{contentId}/{versionNo}/{languageCode}/{referrerLocationId}/cancel + defaults: + _controller: 'EzSystems\EzPlatformAdminUiBundle\Controller\ContentEditController::cancelEditVersionDraftAction' + ezplatform.content.draft.create: path: /content/create/draft/{contentId}/{fromVersionNo}/{fromLanguage}/{toLanguage} defaults: diff --git a/src/bundle/Resources/views/themes/admin/content/edit/edit.html.twig b/src/bundle/Resources/views/themes/admin/content/edit/edit.html.twig index 9552620747..b5704249da 100644 --- a/src/bundle/Resources/views/themes/admin/content/edit/edit.html.twig +++ b/src/bundle/Resources/views/themes/admin/content/edit/edit.html.twig @@ -7,11 +7,32 @@ {% endblock %} {% block page_title %} - {% include '@ezdesign/content/page_title_edit.html.twig' with { + {% embed '@ezdesign/content/page_title_edit.html.twig' with { action_name: 'editing'|trans|desc('Editing'), title: content.name, + content: content, description: content_type.description } %} + {% block close_button %} + {% if without_close_button is not defined or without_close_button != true %} + {% set referrer_location = is_published ? location : parent_location %} + {% set cancel_path = path('ibexa.content.draft.edit.cancel', { + 'contentId': content.id, + 'referrerLocationId': referrer_location.id, + 'versionNo': content.versionInfo.versionNo, + 'languageCode': language.languageCode + }) %} + + + + + + {% endif %} + {% endblock %} + {% endembed %}