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 + }) %} + <a class="ez-content-edit-container__close" + href="{{ cancel_path }}" + title="{{ 'tooltip.exit_label'|trans({}, 'content')|desc('Exit') }}" + > + <svg class="ez-icon ez-icon--small ez-icon--primary"> + <use xlink:href="{{ ez_icon_path('discard') }}"></use> + </svg> + </a> + {% endif %} + {% endblock %} + {% endembed %} <div class="ez-content-item__errors-wrapper" hidden> {{ 'errors.in.the.form'|trans({},'content_edit')|desc('Cannot save the form. Check required Fields or validation errors.') }} diff --git a/src/lib/Event/CancelEditVersionDraftEvent.php b/src/lib/Event/CancelEditVersionDraftEvent.php new file mode 100644 index 0000000000..b8443c8904 --- /dev/null +++ b/src/lib/Event/CancelEditVersionDraftEvent.php @@ -0,0 +1,54 @@ +<?php + +/** + * @copyright Copyright (C) Ibexa AS. All rights reserved. + * @license For full copyright and license information view LICENSE file distributed with this source code. + */ +declare(strict_types=1); + +namespace Ibexa\AdminUi\Event; + +use eZ\Publish\API\Repository\Values\Content\Content; +use eZ\Publish\API\Repository\Values\Content\Location; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Contracts\EventDispatcher\Event; + +final class CancelEditVersionDraftEvent extends Event +{ + /** @var \eZ\Publish\API\Repository\Values\Content\Content */ + private $content; + + /** @var \eZ\Publish\API\Repository\Values\Content\Location */ + private $referrerLocation; + + /** @var \Symfony\Component\HttpFoundation\Response|null */ + private $response; + + public function __construct( + Content $content, + Location $referrerLocation + ) { + $this->content = $content; + $this->referrerLocation = $referrerLocation; + } + + public function getContent(): Content + { + return $this->content; + } + + public function getReferrerLocation(): Location + { + return $this->referrerLocation; + } + + public function getResponse(): ?Response + { + return $this->response; + } + + public function setResponse(?Response $response): void + { + $this->response = $response; + } +}