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 ffddc5427a..0c9dcede5a 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 @@ -6,8 +6,7 @@ {% block header %} {% 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 + 'form_view': form, }) %} {% include '@ibexadesign/ui/edit_header.html.twig' with { @@ -86,6 +85,7 @@ {{ form_widget(form.saveContentType, { attr: { hidden: 'hidden' }}) }} {{ form_widget(form.publishContentType, { attr: { class: 'ibexa-content-type-edit__publish-content-type', hidden: 'hidden' }}) }} + {{ form_widget(form.removeDraft, { attr: { hidden: 'hidden', formnovalidate: true }}) }} {{ form_widget(form._token) }} {{ form_end(form, {'render_rest': false }) }} diff --git a/src/lib/Menu/Admin/ContentType/AbstractContentTypeRightSidebarBuilder.php b/src/lib/Menu/Admin/ContentType/AbstractContentTypeRightSidebarBuilder.php new file mode 100644 index 0000000000..521d624ae6 --- /dev/null +++ b/src/lib/Menu/Admin/ContentType/AbstractContentTypeRightSidebarBuilder.php @@ -0,0 +1,55 @@ +factory->createItem('root'); + + $itemSaveIdentifier = $this->getItemSaveIdentifier(); + $itemCancelIdentifier = $this->getItemCancelIdentifier(); + + $menu->setChildren([ + $itemSaveIdentifier => $this->createMenuItem( + $itemSaveIdentifier, + [ + 'attributes' => [ + 'class' => 'ibexa-btn--trigger ibexa-btn--save-content-type', + 'data-click' => sprintf('#%s', $contentTypeFormView['publishContentType']->vars['id']), + ], + ] + ), + $itemCancelIdentifier => $this->createMenuItem( + $itemCancelIdentifier, + [ + 'attributes' => [ + 'class' => 'ibexa-btn--trigger', + 'data-click' => sprintf('#%s', $contentTypeFormView['removeDraft']->vars['id']), + ], + ] + ), + ]); + + 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 c6a6e8f020..457d7e0df3 100644 --- a/src/lib/Menu/Admin/ContentType/ContentTypeCreateRightSidebarBuilder.php +++ b/src/lib/Menu/Admin/ContentType/ContentTypeCreateRightSidebarBuilder.php @@ -7,90 +7,24 @@ namespace Ibexa\AdminUi\Menu\Admin\ContentType; use Ibexa\AdminUi\Menu\Event\ConfigureMenuEvent; -use Ibexa\AdminUi\Menu\MenuItemFactory; -use Ibexa\Contracts\AdminUi\Menu\AbstractBuilder; -use Ibexa\Contracts\Core\Repository\Exceptions as ApiExceptions; 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 */ public const ITEM__SAVE = 'content_type_create__sidebar_right__save'; public 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 \Ibexa\Contracts\Core\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' => 'ibexa-btn--trigger ibexa-btn--save-content-type', - 'data-click' => sprintf('#%s', $saveId), - ], - ] - ), - self::ITEM__CANCEL => $this->createMenuItem( - self::ITEM__CANCEL, - [ - 'route' => 'ibexa.content_type_group.view', - 'routeParameters' => [ - 'contentTypeGroupId' => $group->id, - ], - ] - ), - ]); - - return $menu; - } - /** * @return \JMS\TranslationBundle\Model\Message[] */ @@ -101,6 +35,16 @@ public static function getTranslationMessages(): array (new Message(self::ITEM__CANCEL, 'menu'))->setDesc('Cancel'), ]; } + + public function getItemSaveIdentifier(): string + { + return self::ITEM__SAVE; + } + + public function getItemCancelIdentifier(): string + { + return self::ITEM__CANCEL; + } } class_alias(ContentTypeCreateRightSidebarBuilder::class, 'EzSystems\EzPlatformAdminUi\Menu\Admin\ContentType\ContentTypeCreateRightSidebarBuilder'); diff --git a/src/lib/Menu/Admin/ContentType/ContentTypeEditRightSidebarBuilder.php b/src/lib/Menu/Admin/ContentType/ContentTypeEditRightSidebarBuilder.php index a728a60ccf..af5168029a 100644 --- a/src/lib/Menu/Admin/ContentType/ContentTypeEditRightSidebarBuilder.php +++ b/src/lib/Menu/Admin/ContentType/ContentTypeEditRightSidebarBuilder.php @@ -7,88 +7,24 @@ namespace Ibexa\AdminUi\Menu\Admin\ContentType; use Ibexa\AdminUi\Menu\Event\ConfigureMenuEvent; -use Ibexa\AdminUi\Menu\MenuItemFactory; -use Ibexa\Contracts\AdminUi\Menu\AbstractBuilder; -use Ibexa\Contracts\Core\Repository\Exceptions as ApiExceptions; 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 */ public const ITEM__SAVE = 'content_type_edit__sidebar_right__save'; public 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' => 'ibexa-btn--trigger ibexa-btn--save-content-type', - 'data-click' => sprintf('#%s', $contentTypeEditFormView['publishContentType']->vars['id']), - ], - ] - ), - self::ITEM__CANCEL => $this->createMenuItem( - self::ITEM__CANCEL, - [ - 'attributes' => [ - 'class' => 'ibexa-btn--trigger', - 'data-click' => sprintf('#%s', $contentTypeEditFormView['removeDraft']->vars['id']), - ], - ] - ), - ]); - - return $menu; - } - /** * @return \JMS\TranslationBundle\Model\Message[] */ @@ -99,6 +35,16 @@ public static function getTranslationMessages(): array (new Message(self::ITEM__CANCEL, 'menu'))->setDesc('Cancel'), ]; } + + public function getItemSaveIdentifier(): string + { + return self::ITEM__SAVE; + } + + public function getItemCancelIdentifier(): string + { + return self::ITEM__CANCEL; + } } class_alias(ContentTypeEditRightSidebarBuilder::class, 'EzSystems\EzPlatformAdminUi\Menu\Admin\ContentType\ContentTypeEditRightSidebarBuilder');