Skip to content

Commit

Permalink
IBX-6276: Added removing content type draft when clicking cancel butt…
Browse files Browse the repository at this point in the history
…on (#2107)
  • Loading branch information
ciastektk authored Aug 3, 2023
1 parent 0ceabb1 commit 53d5680
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,14 @@

{{ form_widget(form.saveContentType, { attr: { hidden: 'hidden' }}) }}
{{ form_widget(form.publishContentType, { attr: { hidden: 'hidden' }}) }}
{{ form_widget(form.removeDraft, {'attr': { 'hidden': 'hidden' }}) }}

{{ form_widget(form._token) }}
{{ form_end(form, {'render_rest': false }) }}
{% endblock %}

{% block right_sidebar %}
{% set content_type_create_sidebar_right = knp_menu_get('ezplatform_admin_ui.menu.content_type_create.sidebar_right', [], {'save_id': form.publishContentType.vars.id, 'group': content_type_group}) %}
{% set content_type_create_sidebar_right = knp_menu_get('ezplatform_admin_ui.menu.content_type_create.sidebar_right', [], {'form_view': form}) %}
{{ knp_menu_render(content_type_create_sidebar_right, {'template': '@ezdesign/ui/menu/sidebar_right.html.twig'}) }}
{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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 EzSystems\EzPlatformAdminUi\Menu\Admin\ContentType;

use EzSystems\EzPlatformAdminUi\Menu\AbstractBuilder;
use JMS\TranslationBundle\Translation\TranslationContainerInterface;
use Knp\Menu\ItemInterface;

abstract class AbstractContentTypeRightSidebarBuilder extends AbstractBuilder implements TranslationContainerInterface
{
public function createStructure(array $options): ItemInterface
{
/** @var \Symfony\Component\Form\FormView $contentTypeFormView */
$contentTypeFormView = $options['form_view'];

/** @var \Knp\Menu\ItemInterface|\Knp\Menu\ItemInterface[] $menu */
$menu = $this->factory->createItem('root');

$itemSaveIdentifier = $this->getItemSaveIdentifier();
$itemCancelIdentifier = $this->getItemCancelIdentifier();

$menu->setChildren([
$itemSaveIdentifier => $this->createMenuItem(
$itemSaveIdentifier,
[
'attributes' => [
'class' => 'btn--trigger',
'data-click' => sprintf('#%s', $contentTypeFormView['publishContentType']->vars['id']),
],
'extras' => ['icon' => 'save'],
]
),
$itemCancelIdentifier => $this->createMenuItem(
$itemCancelIdentifier,
[
'attributes' => [
'class' => 'btn--trigger',
'data-click' => sprintf('#%s', $contentTypeFormView['removeDraft']->vars['id']),
],
'extras' => ['icon' => 'circle-close'],
]
),
]);

return $menu;
}

abstract public function getItemSaveIdentifier(): string;

abstract public function getItemCancelIdentifier(): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,93 +6,25 @@
*/
namespace EzSystems\EzPlatformAdminUi\Menu\Admin\ContentType;

use eZ\Publish\API\Repository\Exceptions as ApiExceptions;
use EzSystems\EzPlatformAdminUi\Menu\AbstractBuilder;
use EzSystems\EzPlatformAdminUi\Menu\Event\ConfigureMenuEvent;
use EzSystems\EzPlatformAdminUi\Menu\MenuItemFactory;
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Translation\TranslationContainerInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* KnpMenuBundle Menu Builder service implementation for AdminUI Section Edit contextual sidebar menu.
*
* @see https://symfony.com/doc/current/bundles/KnpMenuBundle/menu_builder_service.html
*/
class ContentTypeCreateRightSidebarBuilder extends AbstractBuilder implements TranslationContainerInterface
class ContentTypeCreateRightSidebarBuilder extends AbstractContentTypeRightSidebarBuilder
{
/* Menu items */
const ITEM__SAVE = 'content_type_create__sidebar_right__save';
const ITEM__CANCEL = 'content_type_create__sidebar_right__cancel';

/** @var \Symfony\Contracts\Translation\TranslatorInterface */
private $translator;

public function __construct(
MenuItemFactory $factory,
EventDispatcherInterface $eventDispatcher,
TranslatorInterface $translator
) {
parent::__construct($factory, $eventDispatcher);

$this->translator = $translator;
}

/**
* @return string
*/
protected function getConfigureEventName(): string
{
return ConfigureMenuEvent::CONTENT_TYPE_CREATE_SIDEBAR_RIGHT;
}

/**
* @param array $options
*
* @return \Knp\Menu\ItemInterface
*
* @throws \InvalidArgumentException
* @throws ApiExceptions\BadStateException
* @throws \InvalidArgumentException
*/
public function createStructure(array $options): ItemInterface
{
/** @var \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup $section */
$group = $options['group'];

$saveId = $options['save_id'];

/** @var \Knp\Menu\ItemInterface|\Knp\Menu\ItemInterface[] $menu */
$menu = $this->factory->createItem('root');

$menu->setChildren([
self::ITEM__SAVE => $this->createMenuItem(
self::ITEM__SAVE,
[
'attributes' => [
'class' => 'btn--trigger',
'data-click' => sprintf('#%s', $saveId),
],
'extras' => ['icon' => 'publish'],
]
),
self::ITEM__CANCEL => $this->createMenuItem(
self::ITEM__CANCEL,
[
'extras' => ['icon' => 'circle-close'],
'route' => 'ezplatform.content_type_group.view',
'routeParameters' => [
'contentTypeGroupId' => $group->id,
],
]
),
]);

return $menu;
}

/**
* @return \JMS\TranslationBundle\Model\Message[]
*/
Expand All @@ -103,4 +35,14 @@ public static function getTranslationMessages(): array
(new Message(self::ITEM__CANCEL, 'menu'))->setDesc('Discard changes'),
];
}

public function getItemSaveIdentifier(): string
{
return self::ITEM__SAVE;
}

public function getItemCancelIdentifier(): string
{
return self::ITEM__CANCEL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,91 +6,25 @@
*/
namespace EzSystems\EzPlatformAdminUi\Menu\Admin\ContentType;

use eZ\Publish\API\Repository\Exceptions as ApiExceptions;
use EzSystems\EzPlatformAdminUi\Menu\AbstractBuilder;
use EzSystems\EzPlatformAdminUi\Menu\Event\ConfigureMenuEvent;
use EzSystems\EzPlatformAdminUi\Menu\MenuItemFactory;
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Translation\TranslationContainerInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* KnpMenuBundle Menu Builder service implementation for AdminUI Section Edit contextual sidebar menu.
*
* @see https://symfony.com/doc/current/bundles/KnpMenuBundle/menu_builder_service.html
*/
class ContentTypeEditRightSidebarBuilder extends AbstractBuilder implements TranslationContainerInterface
class ContentTypeEditRightSidebarBuilder extends AbstractContentTypeRightSidebarBuilder
{
/* Menu items */
const ITEM__SAVE = 'content_type_edit__sidebar_right__save';
const ITEM__CANCEL = 'content_type_edit__sidebar_right__cancel';

/** @var \Symfony\Contracts\Translation\TranslatorInterface */
private $translator;

public function __construct(
MenuItemFactory $factory,
EventDispatcherInterface $eventDispatcher,
TranslatorInterface $translator
) {
parent::__construct($factory, $eventDispatcher);

$this->translator = $translator;
}

/**
* @return string
*/
protected function getConfigureEventName(): string
{
return ConfigureMenuEvent::CONTENT_TYPE_EDIT_SIDEBAR_RIGHT;
}

/**
* @param array $options
*
* @return \Knp\Menu\ItemInterface
*
* @throws \InvalidArgumentException
* @throws ApiExceptions\BadStateException
* @throws \InvalidArgumentException
*/
public function createStructure(array $options): ItemInterface
{
/** @var \Symfony\Component\Form\FormView $contentTypeEditFormView */
$contentTypeEditFormView = $options['form_view'];

/** @var \Knp\Menu\ItemInterface|\Knp\Menu\ItemInterface[] $menu */
$menu = $this->factory->createItem('root');

$menu->setChildren([
self::ITEM__SAVE => $this->createMenuItem(
self::ITEM__SAVE,
[
'attributes' => [
'class' => 'btn--trigger',
'data-click' => sprintf('#%s', $contentTypeEditFormView['publishContentType']->vars['id']),
],
'extras' => ['icon' => 'save'],
]
),
self::ITEM__CANCEL => $this->createMenuItem(
self::ITEM__CANCEL,
[
'attributes' => [
'class' => 'btn--trigger',
'data-click' => sprintf('#%s', $contentTypeEditFormView['removeDraft']->vars['id']),
],
'extras' => ['icon' => 'circle-close'],
]
),
]);

return $menu;
}

/**
* @return \JMS\TranslationBundle\Model\Message[]
*/
Expand All @@ -101,4 +35,14 @@ public static function getTranslationMessages(): array
(new Message(self::ITEM__CANCEL, 'menu'))->setDesc('Discard changes'),
];
}

public function getItemSaveIdentifier(): string
{
return self::ITEM__SAVE;
}

public function getItemCancelIdentifier(): string
{
return self::ITEM__CANCEL;
}
}

0 comments on commit 53d5680

Please sign in to comment.