Skip to content

Commit

Permalink
IBX-431: Allowed interception of canceling the draft version edit (#1876
Browse files Browse the repository at this point in the history
)

* IBX-431: Allowed interception of canceling the draft version edit

* fix: Readability

* fix: Code review
  • Loading branch information
Nattfarinn authored Aug 31, 2021
1 parent 5aacec3 commit 429f955
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/bundle/Controller/ContentEditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
}
5 changes: 5 additions & 0 deletions src/bundle/Resources/config/routing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.') }}
Expand Down
54 changes: 54 additions & 0 deletions src/lib/Event/CancelEditVersionDraftEvent.php
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 429f955

Please sign in to comment.