Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added removing content type draft when clicking cancel button #846

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -86,6 +85,7 @@
</div>
{{ 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 }) }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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\Menu\Admin\ContentType;

use Ibexa\Contracts\AdminUi\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' => '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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
*/
Expand All @@ -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');
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
*/
Expand All @@ -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');