diff --git a/src/bundle/Resources/config/services/menu.yml b/src/bundle/Resources/config/services/menu.yml index 1b53aa88b5..abeadddc9b 100644 --- a/src/bundle/Resources/config/services/menu.yml +++ b/src/bundle/Resources/config/services/menu.yml @@ -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 } diff --git a/src/bundle/Resources/views/admin/trash/list.html.twig b/src/bundle/Resources/views/admin/trash/list.html.twig index 328cc8ceed..ef80f6573a 100644 --- a/src/bundle/Resources/views/admin/trash/list.html.twig +++ b/src/bundle/Resources/views/admin/trash/list.html.twig @@ -69,15 +69,8 @@
- {% if can_delete %} - - {% 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'}) }}
{% endblock %} diff --git a/src/lib/Menu/Event/ConfigureMenuEvent.php b/src/lib/Menu/Event/ConfigureMenuEvent.php index bf2c97d4f6..f769086d53 100644 --- a/src/lib/Menu/Event/ConfigureMenuEvent.php +++ b/src/lib/Menu/Event/ConfigureMenuEvent.php @@ -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; diff --git a/src/lib/Menu/TrashRightSidebarBuilder.php b/src/lib/Menu/TrashRightSidebarBuilder.php new file mode 100644 index 0000000000..b7f837c6eb --- /dev/null +++ b/src/lib/Menu/TrashRightSidebarBuilder.php @@ -0,0 +1,102 @@ +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'), + ]; + } +}