From 931460417bac14d0465ee921d1a1e33153778704 Mon Sep 17 00:00:00 2001 From: Maciej Kobus Date: Tue, 24 Oct 2017 15:39:06 +0200 Subject: [PATCH] EZP-28127: Create extendable left sidebar --- src/bundle/Resources/config/services/menu.yml | 5 ++ .../views/admin/trash/list.html.twig | 19 +---- .../views/content/locationview.html.twig | 19 +---- .../views/parts/menu/sidebar_left.html.twig | 41 +++++++++++ src/lib/Menu/LeftSidebarBuilder.php | 71 +++++++++++++++++++ 5 files changed, 119 insertions(+), 36 deletions(-) create mode 100644 src/bundle/Resources/views/parts/menu/sidebar_left.html.twig create mode 100644 src/lib/Menu/LeftSidebarBuilder.php diff --git a/src/bundle/Resources/config/services/menu.yml b/src/bundle/Resources/config/services/menu.yml index 2ce769c15c..888a9bc59d 100644 --- a/src/bundle/Resources/config/services/menu.yml +++ b/src/bundle/Resources/config/services/menu.yml @@ -12,3 +12,8 @@ services: public: true tags: - { name: knp_menu.menu_builder, method: build, alias: ezplatform_admin_ui.menu.main } + + EzSystems\EzPlatformAdminUi\Menu\LeftSidebarBuilder: + public: true + tags: + - { name: knp_menu.menu_builder, method: build, alias: ezplatform_admin_ui.menu.content.sidebar_left } diff --git a/src/bundle/Resources/views/admin/trash/list.html.twig b/src/bundle/Resources/views/admin/trash/list.html.twig index 44232c7db8..911eca0895 100644 --- a/src/bundle/Resources/views/admin/trash/list.html.twig +++ b/src/bundle/Resources/views/admin/trash/list.html.twig @@ -8,24 +8,7 @@
{# @todo sidebars should be moved to layout.html.twig !! #} - - - - - - - Trash - + {{ knp_menu_render('ezplatform_admin_ui.menu.content.sidebar_left', {'template': '@EzPlatformAdminUi/parts/menu/sidebar_left.html.twig'}) }}
diff --git a/src/bundle/Resources/views/content/locationview.html.twig b/src/bundle/Resources/views/content/locationview.html.twig index b9adaf9d25..2f35b1da2f 100644 --- a/src/bundle/Resources/views/content/locationview.html.twig +++ b/src/bundle/Resources/views/content/locationview.html.twig @@ -15,24 +15,7 @@ data-parent-content-type-id="{{ contentType.id }}">
- - - - - - - Trash - + {{ knp_menu_render('ezplatform_admin_ui.menu.content.sidebar_left', {'template': '@EzPlatformAdminUi/parts/menu/sidebar_left.html.twig'}) }}
diff --git a/src/bundle/Resources/views/parts/menu/sidebar_left.html.twig b/src/bundle/Resources/views/parts/menu/sidebar_left.html.twig new file mode 100644 index 0000000000..c59998cc28 --- /dev/null +++ b/src/bundle/Resources/views/parts/menu/sidebar_left.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('') ~ ' 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/lib/Menu/LeftSidebarBuilder.php b/src/lib/Menu/LeftSidebarBuilder.php new file mode 100644 index 0000000000..bda0aeecc4 --- /dev/null +++ b/src/lib/Menu/LeftSidebarBuilder.php @@ -0,0 +1,71 @@ +factory->createItem('root'); + + $menu->addChild( + $this->createMenuItem('sidebar_left__search', [ + 'extras' => ['icon' => 'search'], + 'attributes' => [ + 'disabled' => 'disabled', + ], + ]) + ); + $menu->addChild( + $this->createMenuItem('sidebar_left__browse', [ + 'extras' => ['icon' => 'browse'], + 'attributes' => [ + 'class' => 'btn--udw-browse', + 'data-starting-location-id' => 1, + ], + ]) + ); + $menu->addChild($this->createMenuItem('sidebar_left__trash', [ + 'route' => 'ezplatform.trash.list', + 'extras' => ['icon' => 'trash'], + ])); + + return $menu; + } + + /** + * @return array + */ + public static function getTranslationMessages(): array + { + return [ + (new Message('sidebar_left__search', 'menu'))->setDesc('Search'), + (new Message('sidebar_left__browse', 'menu'))->setDesc('Browse'), + (new Message('sidebar_left__trash', 'menu'))->setDesc('Trash'), + ]; + } +}