-
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-28127: Create extendable left sidebar
- Loading branch information
Showing
5 changed files
with
142 additions
and
36 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
41 changes: 41 additions & 0 deletions
41
src/bundle/Resources/views/parts/menu/sidebar_left.html.twig
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,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 %} |
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,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'), | ||
]; | ||
} | ||
} |