Skip to content

Commit

Permalink
EZP-28131: Added extendable right sidebar in Trash
Browse files Browse the repository at this point in the history
  • Loading branch information
webhdx committed Oct 31, 2017
1 parent bc60fac commit 629e3ed
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/bundle/Resources/config/services/menu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ services:
public: true
tags:
- { name: knp_menu.menu_builder, method: build, alias: ezplatform_admin_ui.menu.content.sidebar_right }

EzSystems\EzPlatformAdminUi\Menu\TrashRightSidebarBuilder:
public: true
tags:
- { name: knp_menu.menu_builder, method: build, alias: ezplatform_admin_ui.menu.trash.sidebar_right }
11 changes: 2 additions & 9 deletions src/bundle/Resources/views/admin/trash/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,8 @@
</section>
</div>
<div class="col-sm-1 pt-4 bg-secondary ez-context-menu">
{% if can_delete %}
<button type="button"
class="btn btn-secondary btn-block{% if trash_items|length == 0 %} disabled{% endif %}"{% if trash_items|length > 0 %} data-toggle="modal" data-target="#confirmEmptyTrash"{% endif %}>
<svg class="ez-icon ez-icon-trash-empty">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#trash-empty"></use>
</svg>
{{ 'trash.empty_trash'|trans|desc('Empty Trash') }}
</button>
{% endif %}
{% set sidebar_right = knp_menu_get('ezplatform_admin_ui.menu.trash.sidebar_right', []) %}
{{ knp_menu_render(sidebar_right, {'template': '@EzPlatformAdminUi/parts/menu/sidebar_right.html.twig'}) }}
</div>
</div>
{% endblock %}
Expand Down
1 change: 1 addition & 0 deletions src/lib/Menu/Event/ConfigureMenuEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ConfigureMenuEvent extends Event
const MAIN_MENU = 'ezplatform_admin_ui.menu_configure.main_menu';
const CONTENT_SIDEBAR_RIGHT = 'ezplatform_admin_ui.menu_configure.content_sidebar_right';
const CONTENT_SIDEBAR_LEFT = 'ezplatform_admin_ui.menu_configure.content_sidebar_left';
const TRASH_SIDEBAR_RIGHT = 'ezplatform_admin_ui.menu_configure.trash_sidebar_right';

/** @var FactoryInterface */
private $factory;
Expand Down
102 changes: 102 additions & 0 deletions src/lib/Menu/TrashRightSidebarBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformAdminUi\Menu;

use eZ\Publish\API\Repository\Exceptions as ApiExceptions;
use eZ\Publish\API\Repository\PermissionResolver;
use eZ\Publish\API\Repository\TrashService;
use eZ\Publish\API\Repository\Values\Content\Query;
use EzSystems\EzPlatformAdminUi\Menu\Event\ConfigureMenuEvent;
use InvalidArgumentException;
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Translation\TranslationContainerInterface;
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* KnpMenuBundle Menu Builder service implementation for AdminUI Trash contextual sidebar menu.
*
* @see https://symfony.com/doc/current/bundles/KnpMenuBundle/menu_builder_service.html
*/
class TrashRightSidebarBuilder extends AbstractBuilder implements TranslationContainerInterface
{
/* Menu items */
const ITEM__EMPTY = 'trash__sidebar_right__empty_trash';

/** @var PermissionResolver */
private $permissionResolver;

/** @var TrashService */
private $trashService;

/**
* @param FactoryInterface $factory
* @param EventDispatcherInterface $eventDispatcher
* @param PermissionResolver $permissionResolver
* @param TrashService $trashService
*/
public function __construct(
FactoryInterface $factory,
EventDispatcherInterface $eventDispatcher,
PermissionResolver $permissionResolver,
TrashService $trashService
) {
parent::__construct($factory, $eventDispatcher);

$this->permissionResolver = $permissionResolver;
$this->trashService = $trashService;
}

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

/**
* @param array $options
*
* @return ItemInterface
*
* @throws ApiExceptions\InvalidArgumentException
* @throws ApiExceptions\BadStateException
* @throws InvalidArgumentException
*/
public function createStructure(array $options): ItemInterface
{
/** @var bool $location */
$canDelete = $this->permissionResolver->hasAccess('content', 'cleantrash');
/** @var int $trashItemsCount */
$trashItemsCount = $this->trashService->findTrashItems(new Query())->count;
/** @var ItemInterface|ItemInterface[] $menu */
$menu = $this->factory->createItem('root');

$menu->addChild(
$this->createMenuItem(self::ITEM__EMPTY, [
'extras' => ['icon' => 'trash-empty'],
'attributes' => $canDelete > 0 && $trashItemsCount > 0
? ['data-toggle' => 'modal', 'data-target' => '#confirmEmptyTrash']
: ['class' => 'disabled'],
])
);

return $menu;
}

/**
* @return array
*/
public static function getTranslationMessages(): array
{
return [
(new Message(self::ITEM__EMPTY, 'menu'))->setDesc('Empty Trash'),
];
}
}

0 comments on commit 629e3ed

Please sign in to comment.