From 53d5680bba39f0bbd24dee64a4db58f51ddcf540 Mon Sep 17 00:00:00 2001 From: ciastektk Date: Thu, 3 Aug 2023 14:56:24 +0200 Subject: [PATCH] IBX-6276: Added removing content type draft when clicking cancel button (#2107) --- .../admin/content_type/create.html.twig | 3 +- ...AbstractContentTypeRightSidebarBuilder.php | 57 +++++++++++++ .../ContentTypeCreateRightSidebarBuilder.php | 80 +++---------------- .../ContentTypeEditRightSidebarBuilder.php | 78 +++--------------- 4 files changed, 81 insertions(+), 137 deletions(-) create mode 100644 src/lib/Menu/Admin/ContentType/AbstractContentTypeRightSidebarBuilder.php diff --git a/src/bundle/Resources/views/themes/admin/content_type/create.html.twig b/src/bundle/Resources/views/themes/admin/content_type/create.html.twig index b370262490..4fedd94dea 100644 --- a/src/bundle/Resources/views/themes/admin/content_type/create.html.twig +++ b/src/bundle/Resources/views/themes/admin/content_type/create.html.twig @@ -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 %} diff --git a/src/lib/Menu/Admin/ContentType/AbstractContentTypeRightSidebarBuilder.php b/src/lib/Menu/Admin/ContentType/AbstractContentTypeRightSidebarBuilder.php new file mode 100644 index 0000000000..4ca806d8e3 --- /dev/null +++ b/src/lib/Menu/Admin/ContentType/AbstractContentTypeRightSidebarBuilder.php @@ -0,0 +1,57 @@ +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; +} diff --git a/src/lib/Menu/Admin/ContentType/ContentTypeCreateRightSidebarBuilder.php b/src/lib/Menu/Admin/ContentType/ContentTypeCreateRightSidebarBuilder.php index b5d8721042..df7ea24bec 100644 --- a/src/lib/Menu/Admin/ContentType/ContentTypeCreateRightSidebarBuilder.php +++ b/src/lib/Menu/Admin/ContentType/ContentTypeCreateRightSidebarBuilder.php @@ -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[] */ @@ -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; + } } diff --git a/src/lib/Menu/Admin/ContentType/ContentTypeEditRightSidebarBuilder.php b/src/lib/Menu/Admin/ContentType/ContentTypeEditRightSidebarBuilder.php index 0a585e44ae..a03aee346a 100644 --- a/src/lib/Menu/Admin/ContentType/ContentTypeEditRightSidebarBuilder.php +++ b/src/lib/Menu/Admin/ContentType/ContentTypeEditRightSidebarBuilder.php @@ -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[] */ @@ -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; + } }