Skip to content

Commit

Permalink
EZP-28127: Create extendable left sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
webhdx committed Oct 25, 2017
1 parent cc0ad6e commit 0559285
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 36 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 @@ -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 }
19 changes: 1 addition & 18 deletions src/bundle/Resources/views/admin/trash/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,7 @@
<div id="react-udw"></div>
<div class="row align-items-stretch ez-main-row">
<div class="col-sm-1 bg-dark pt-4 ez-side-menu"> {# @todo sidebars should be moved to layout.html.twig !! #}
<button class="btn btn-dark btn-block" disabled>
<svg class="ez-icon ez-icon-search">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#search"></use>
</svg>
Search
</button>
<button class="btn btn-dark btn-block btn--udw-browse" data-starting-location-id="2">
<svg class="ez-icon ez-icon-browse">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#browse"></use>
</svg>
Browse
</button>
<a class="btn btn-dark btn-block" href="{{ path('ezplatform.trash.list') }}">
<svg class="ez-icon ez-icon-trash">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#trash"></use>
</svg>
Trash
</a>
{{ knp_menu_render('ezplatform_admin_ui.menu.content.sidebar_left', {'template': '@EzPlatformAdminUi/parts/menu/sidebar_left.html.twig'}) }}
</div>
<div class="col-sm-10 px-0">
<section class="container mt-5">
Expand Down
19 changes: 1 addition & 18 deletions src/bundle/Resources/views/content/locationview.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,7 @@
data-parent-content-type-id="{{ contentType.id }}"></div>
<div class="row align-items-stretch ez-main-row">
<div class="col-sm-1 bg-dark pt-4 ez-side-menu">
<button class="btn btn-dark btn-block" disabled>
<svg class="ez-icon ez-icon-search">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#search"></use>
</svg>
Search
</button>
<button class="btn btn-dark btn-block btn--udw-browse" data-starting-location-id="2">
<svg class="ez-icon ez-icon-browse">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#browse"></use>
</svg>
Browse
</button>
<a class="btn btn-dark btn-block" href="{{ path('ezplatform.trash.list') }}">
<svg class="ez-icon ez-icon-trash">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#trash"></use>
</svg>
Trash
</a>
{{ knp_menu_render('ezplatform_admin_ui.menu.content.sidebar_left', {'template': '@EzPlatformAdminUi/parts/menu/sidebar_left.html.twig'}) }}
</div>
<div class="col-sm-10 px-0 pb-4">
<div class="ez-header pt-4">
Expand Down
41 changes: 41 additions & 0 deletions src/bundle/Resources/views/parts/menu/sidebar_left.html.twig
Original file line number Diff line number Diff line change
@@ -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') }}
</{{ element }}>
{% endblock %}

{% block label %}
{% if item.extras.icon is defined and item.extras.icon != '' %}
<svg class="ez-icon ez-icon-{{ item.extras.icon }}">
<use xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#{{ item.extras.icon }}"></use>
</svg>
{% endif %}
{{ parent() }}
{% endblock %}
94 changes: 94 additions & 0 deletions src/lib/Menu/LeftSidebarBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?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\Core\MVC\ConfigResolverInterface;
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;

class LeftSidebarBuilder extends AbstractBuilder implements TranslationContainerInterface
{
/** @var ConfigResolverInterface */
private $configResolver;

/**
* @param FactoryInterface $factory
* @param EventDispatcherInterface $eventDispatcher
* @param ConfigResolverInterface $configResolver
*/
public function __construct(
FactoryInterface $factory,
EventDispatcherInterface $eventDispatcher,
ConfigResolverInterface $configResolver
)
{
parent::__construct($factory, $eventDispatcher);

$this->configResolver = $configResolver;
}

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

/**
* @param array $options
*
* @return ItemInterface
* @throws InvalidArgumentException
*/
public function createStructure(array $options): ItemInterface
{
$menu = $this->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'),
];
}
}

0 comments on commit 0559285

Please sign in to comment.