-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZP-28131: Added extendable right sidebar in Trash
- Loading branch information
Showing
4 changed files
with
110 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
]; | ||
} | ||
} |