-
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.
Merge pull request #30 from webhdx/right_sidebar
EZP-28131: Create extendable right sidebar
- Loading branch information
Showing
9 changed files
with
269 additions
and
65 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_base.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('') ~ ' ' ~ 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') }} | ||
</{{ 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 %} |
41 changes: 3 additions & 38 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 |
---|---|---|
@@ -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') }} | ||
</{{ 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 %} | ||
{%- set default_classes = 'btn btn-dark btn-block' -%} | ||
{{ parent() }} | ||
{% endblock %} | ||
{%- endblock %} |
6 changes: 6 additions & 0 deletions
6
src/bundle/Resources/views/parts/menu/sidebar_right.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,6 @@ | ||
{% extends 'EzPlatformAdminUiBundle:parts/menu:sidebar_base.html.twig' %} | ||
|
||
{% block item -%} | ||
{%- set default_classes = 'btn btn-secondary btn-block' -%} | ||
{{ 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,102 @@ | ||
<?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\API\Repository\Values\Content\Location; | ||
use EzSystems\EzPlatformAdminUi\Menu\Event\ConfigureMenuEvent; | ||
use InvalidArgumentException; | ||
use JMS\TranslationBundle\Model\Message; | ||
use JMS\TranslationBundle\Translation\TranslationContainerInterface; | ||
use Knp\Menu\ItemInterface; | ||
|
||
/** | ||
* KnpMenuBundle Menu Builder service implementation for AdminUI Location View contextual sidebar menu. | ||
* | ||
* @see https://symfony.com/doc/current/bundles/KnpMenuBundle/menu_builder_service.html | ||
*/ | ||
class ContentRightSidebarBuilder extends AbstractBuilder implements TranslationContainerInterface | ||
{ | ||
/* Menu items */ | ||
const ITEM__SEND_TO_TRASH = 'content__sidebar_right__send_to_trash'; | ||
const ITEM__COPY = 'content__sidebar_right__copy'; | ||
const ITEM__MOVE = 'content__sidebar_right__move'; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getConfigureEventName(): string | ||
{ | ||
return ConfigureMenuEvent::CONTENT_SIDEBAR_RIGHT; | ||
} | ||
|
||
/** | ||
* @param array $options | ||
* | ||
* @return ItemInterface | ||
* | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function createStructure(array $options): ItemInterface | ||
{ | ||
/** @var Location $location */ | ||
$location = $options['location']; | ||
/** @var ItemInterface|ItemInterface[] $menu */ | ||
$menu = $this->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'), | ||
]; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?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\API\Repository\Exceptions as ApiExceptions; | ||
use eZ\Publish\API\Repository\PermissionResolver; | ||
use eZ\Publish\API\Repository\TrashService; | ||
use eZ\Publish\API\Repository\Values\Content\Query; | ||
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; | ||
|
||
/** | ||
* KnpMenuBundle Menu Builder service implementation for AdminUI Trash contextual sidebar menu. | ||
* | ||
* @see https://symfony.com/doc/current/bundles/KnpMenuBundle/menu_builder_service.html | ||
*/ | ||
class TrashRightSidebarBuilder extends AbstractBuilder implements TranslationContainerInterface | ||
{ | ||
/* Menu items */ | ||
const ITEM__EMPTY = 'trash__sidebar_right__empty_trash'; | ||
|
||
/** @var PermissionResolver */ | ||
private $permissionResolver; | ||
|
||
/** @var TrashService */ | ||
private $trashService; | ||
|
||
/** | ||
* @param FactoryInterface $factory | ||
* @param EventDispatcherInterface $eventDispatcher | ||
* @param PermissionResolver $permissionResolver | ||
* @param TrashService $trashService | ||
*/ | ||
public function __construct( | ||
FactoryInterface $factory, | ||
EventDispatcherInterface $eventDispatcher, | ||
PermissionResolver $permissionResolver, | ||
TrashService $trashService | ||
) { | ||
parent::__construct($factory, $eventDispatcher); | ||
|
||
$this->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'), | ||
]; | ||
} | ||
} |