From bc60fac2305c2fd6595d086fda29655a2e785752 Mon Sep 17 00:00:00 2001 From: Maciej Kobus Date: Wed, 25 Oct 2017 12:25:51 +0200 Subject: [PATCH 1/2] EZP-28131: Added extendable right sidebar in Location View --- src/bundle/Resources/config/services/menu.yml | 5 + .../views/content/locationview.html.twig | 20 +--- .../views/parts/menu/sidebar_base.html.twig | 41 +++++++ .../views/parts/menu/sidebar_left.html.twig | 41 +------ .../views/parts/menu/sidebar_right.html.twig | 6 ++ src/lib/Menu/ContentRightSidebarBuilder.php | 102 ++++++++++++++++++ 6 files changed, 159 insertions(+), 56 deletions(-) create mode 100644 src/bundle/Resources/views/parts/menu/sidebar_base.html.twig create mode 100644 src/bundle/Resources/views/parts/menu/sidebar_right.html.twig create mode 100644 src/lib/Menu/ContentRightSidebarBuilder.php diff --git a/src/bundle/Resources/config/services/menu.yml b/src/bundle/Resources/config/services/menu.yml index 888a9bc59d..1b53aa88b5 100644 --- a/src/bundle/Resources/config/services/menu.yml +++ b/src/bundle/Resources/config/services/menu.yml @@ -17,3 +17,8 @@ services: public: true tags: - { name: knp_menu.menu_builder, method: build, alias: ezplatform_admin_ui.menu.content.sidebar_left } + + EzSystems\EzPlatformAdminUi\Menu\ContentRightSidebarBuilder: + public: true + tags: + - { name: knp_menu.menu_builder, method: build, alias: ezplatform_admin_ui.menu.content.sidebar_right } diff --git a/src/bundle/Resources/views/content/locationview.html.twig b/src/bundle/Resources/views/content/locationview.html.twig index 2f35b1da2f..7fdbb740d4 100644 --- a/src/bundle/Resources/views/content/locationview.html.twig +++ b/src/bundle/Resources/views/content/locationview.html.twig @@ -52,25 +52,9 @@
- - - + {% set content_sidebar_right = knp_menu_get('ezplatform_admin_ui.menu.content.sidebar_right', [], {'location': location}) %} + {{ knp_menu_render(content_sidebar_right, {'template': '@EzPlatformAdminUi/parts/menu/sidebar_right.html.twig'}) }} - {# TODO: location trash should be rendered as a form, confirmation dialog should be impl. as a type #} {% include 'EzPlatformAdminUiBundle:content:modal_location_trash.html.twig' with {'form': form_location_trash} %} {{ form(form_location_copy) }} {{ form(form_location_move) }} diff --git a/src/bundle/Resources/views/parts/menu/sidebar_base.html.twig b/src/bundle/Resources/views/parts/menu/sidebar_base.html.twig new file mode 100644 index 0000000000..5e69ad9653 --- /dev/null +++ b/src/bundle/Resources/views/parts/menu/sidebar_base.html.twig @@ -0,0 +1,41 @@ +{% extends '@KnpMenu/menu.html.twig' %} + +{% block root %} + {% for item in item.children %} + {{ block('item') }} + {% endfor %} +{% endblock %} + +{% block item -%} + {%- if item.displayed -%} + {%- set attributes = item.attributes|merge({'class': (item.attributes.class|default('') ~ ' ' ~ default_classes|default('btn btn-dark btn-block'))|trim}) -%} + {%- set attributes = attributes|merge({'id': item.name ~ '-tab'}) -%} + + {%- if item.uri is not empty %} + {% set attributes = attributes|merge({'href': item.uri}) %} + {% set element = 'a' %} + {{ block('element') }} + {%- else %} + {% set element = 'button' %} + {{ block('element') }} + {%- endif %} + {%- endif -%} +{%- endblock %} + +{% block element %} + {% import 'knp_menu.html.twig' as macros %} + {% set element = element|default('a') %} + <{{ element }}{{ macros.attributes(attributes) }}> + {{ block('label') }} + +{% endblock %} + +{% block label %} + {% if item.extras.icon is defined and item.extras.icon != '' %} + + + + {% endif %} + {{ parent() }} +{% endblock %} diff --git a/src/bundle/Resources/views/parts/menu/sidebar_left.html.twig b/src/bundle/Resources/views/parts/menu/sidebar_left.html.twig index c59998cc28..db54ef9607 100644 --- a/src/bundle/Resources/views/parts/menu/sidebar_left.html.twig +++ b/src/bundle/Resources/views/parts/menu/sidebar_left.html.twig @@ -1,41 +1,6 @@ -{% extends '@KnpMenu/menu.html.twig' %} - -{% block root %} - {% for item in item.children %} - {{ block('item') }} - {% endfor %} -{% endblock %} +{% extends 'EzPlatformAdminUiBundle:parts/menu:sidebar_base.html.twig' %} {% block item -%} - {%- if item.displayed -%} - {%- set attributes = item.attributes|merge({'class': (item.attributes.class|default('') ~ ' btn btn-dark btn-block')|trim}) -%} - {%- set attributes = attributes|merge({'id': item.name ~ '-tab'}) -%} - - {%- if item.uri is not empty %} - {% set attributes = attributes|merge({'href': item.uri}) %} - {% set element = 'a' %} - {{ block('element') }} - {%- else %} - {% set element = 'button' %} - {{ block('element') }} - {%- endif %} - {%- endif -%} -{%- endblock %} - -{% block element %} - {% import 'knp_menu.html.twig' as macros %} - {% set element = element|default('a') %} - <{{ element }}{{ macros.attributes(attributes) }}> - {{ block('label') }} - -{% endblock %} - -{% block label %} - {% if item.extras.icon is defined and item.extras.icon != '' %} - - - - {% endif %} + {%- set default_classes = 'btn btn-dark btn-block' -%} {{ parent() }} -{% endblock %} +{%- endblock %} diff --git a/src/bundle/Resources/views/parts/menu/sidebar_right.html.twig b/src/bundle/Resources/views/parts/menu/sidebar_right.html.twig new file mode 100644 index 0000000000..7c377243a5 --- /dev/null +++ b/src/bundle/Resources/views/parts/menu/sidebar_right.html.twig @@ -0,0 +1,6 @@ +{% extends 'EzPlatformAdminUiBundle:parts/menu:sidebar_base.html.twig' %} + +{% block item -%} + {%- set default_classes = 'btn btn-secondary btn-block' -%} + {{ parent() }} +{%- endblock %} diff --git a/src/lib/Menu/ContentRightSidebarBuilder.php b/src/lib/Menu/ContentRightSidebarBuilder.php new file mode 100644 index 0000000000..6d328c3033 --- /dev/null +++ b/src/lib/Menu/ContentRightSidebarBuilder.php @@ -0,0 +1,102 @@ +factory->createItem('root'); + + $menu->setChildren([ + self::ITEM__SEND_TO_TRASH => $this->createMenuItem( + self::ITEM__SEND_TO_TRASH, + [ + 'extras' => ['icon' => 'trash-send'], + 'attributes' => [ + 'data-toggle' => 'modal', + 'data-target' => '#trash-location-modal', + ], + ] + ), + self::ITEM__COPY => $this->createMenuItem( + self::ITEM__COPY, + [ + 'extras' => ['icon' => 'copy'], + 'attributes' => [ + 'class' => 'btn--udw-copy', + 'data-root-location' => 1, + ], + ] + ), + self::ITEM__MOVE => $this->createMenuItem( + self::ITEM__MOVE, + [ + 'extras' => ['icon' => 'move'], + 'attributes' => [ + 'class' => 'btn--udw-move', + 'data-root-location' => 1, + ], + ] + ), + ]); + + if (1 === $location->depth) { + $menu[self::ITEM__SEND_TO_TRASH]->setAttribute('disabled', 'disabled'); + $menu[self::ITEM__MOVE]->setAttribute('disabled', 'disabled'); + } + + return $menu; + } + + /** + * @return Message[] + */ + public static function getTranslationMessages(): array + { + return [ + (new Message(self::ITEM__SEND_TO_TRASH, 'menu'))->setDesc('Send to Trash'), + (new Message(self::ITEM__COPY, 'menu'))->setDesc('Copy'), + (new Message(self::ITEM__MOVE, 'menu'))->setDesc('Move'), + ]; + } +} From 629e3edc82d316d53ae76546e352b4e5556657d1 Mon Sep 17 00:00:00 2001 From: Maciej Kobus Date: Wed, 25 Oct 2017 14:09:35 +0200 Subject: [PATCH 2/2] EZP-28131: Added extendable right sidebar in Trash --- src/bundle/Resources/config/services/menu.yml | 5 + .../views/admin/trash/list.html.twig | 11 +- src/lib/Menu/Event/ConfigureMenuEvent.php | 1 + src/lib/Menu/TrashRightSidebarBuilder.php | 102 ++++++++++++++++++ 4 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 src/lib/Menu/TrashRightSidebarBuilder.php 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'), + ]; + } +}