Skip to content

Commit

Permalink
EZP-28117: Created new main menu builder with extensibility point
Browse files Browse the repository at this point in the history
  • Loading branch information
webhdx committed Oct 24, 2017
1 parent 0410770 commit cc0ad6e
Show file tree
Hide file tree
Showing 10 changed files with 323 additions and 127 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser;

use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\AbstractParser;
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;

class LocationIds extends AbstractParser
{
/**
* Adds semantic configuration definition.
*
* @param NodeBuilder $nodeBuilder Node just under ezpublish.system.<siteaccess>
*/
public function addSemanticConfig(NodeBuilder $nodeBuilder)
{
$nodeBuilder
->arrayNode('location_ids')
->info('System locations id configuration')
->children()
->scalarNode('content')->isRequired()->end()
->scalarNode('media')->isRequired()->end()
->scalarNode('users')->isRequired()->end()
->end()
->end();
}

public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer)
{
if (empty($scopeSettings['location_ids'])) {
return;
}

$settings = $scopeSettings['location_ids'];
$keys = ['content', 'media', 'users'];

foreach ($keys as $key) {
if (!isset($settings[$key]) || empty($settings[$key])) {
continue;
}

$contextualizer->setContextualParameter(
sprintf('location_ids.%s', $key),
$currentScope,
$settings[$key]
);
}
}
}
5 changes: 4 additions & 1 deletion src/bundle/EzPlatformAdminUiBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension;
use EzSystems\EzPlatformAdminUi\SiteAccess\AdminFilter;
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Compiler\MenuPass;
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Compiler\SystemInfoTabGroupPass;
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Compiler\TabPass;
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Compiler\UiConfigProviderPass;
use EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Configuration\Parser\LocationIds;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

Expand All @@ -25,6 +25,9 @@ public function build(ContainerBuilder $container)
new AdminFilter()
);

$core->addConfigParser(new LocationIds());
$core->addDefaultSettings(__DIR__ . '/Resources/config', ['ezpublish_default_settings.yml']);

$this->addCompilerPasses($container);
}

Expand Down
4 changes: 4 additions & 0 deletions src/bundle/Resources/config/ezpublish_default_settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
ezsettings.default.location_ids.content: 2
ezsettings.default.location_ids.media: 43
ezsettings.default.location_ids.users: 5
125 changes: 5 additions & 120 deletions src/bundle/Resources/config/services/menu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,126 +4,11 @@ services:
autoconfigure: true
public: true

EzSystems\EzPlatformAdminUi\Menu\Registry:
#
# Menu Builders
#

#KNP Builders
EzSystems\EzPlatformAdminUi\Menu\Builder:
EzSystems\EzPlatformAdminUi\Menu\MainMenuBuilder:
public: true
arguments:
$identifier: 'main'
tags:
- { name: knp_menu.menu_builder, method: createMainMenu, alias: main }

#Menus
ezplatform.menu.main:
class: EzSystems\EzPlatformAdminUi\Menu\Menu
arguments:
$identifier: 'main'
tags:
- { name: ezplatform.menu, identifier: main }

ezplatform.menu.main.content:
class: EzSystems\EzPlatformAdminUi\Menu\Item
arguments:
$identifier: content
$icon: 'content-list'
tags:
- { name: ezplatform.menu.item, parent: ezplatform.menu.main, priority: 10 }

ezplatform.menu.main.content.structure:
class: EzSystems\EzPlatformAdminUi\Menu\Item
arguments:
$identifier: content_structure
$name: 'Content Structure'
$url: { route: _ezpublishLocation, routeParameters: { locationId: 2 } }
tags:
- { name: ezplatform.menu.item, parent: ezplatform.menu.main.content, priority: 10 }

ezplatform.menu.main.content.media:
class: EzSystems\EzPlatformAdminUi\Menu\Item
arguments:
$identifier: media
$url: { route: _ezpublishLocation, routeParameters: { locationId: 43 } }
tags:
- { name: ezplatform.menu.item, parent: ezplatform.menu.main.content, priority: 10 }

ezplatform.menu.main.admin:
class: EzSystems\EzPlatformAdminUi\Menu\Item
arguments:
$identifier: admin
$icon: 'panel'
tags:
- { name: ezplatform.menu.item, parent: ezplatform.menu.main, priority: 20 }

ezplatform.menu.main.admin.systeminfo:
class: EzSystems\EzPlatformAdminUi\Menu\Item
arguments:
$identifier: systeminfo
$name: 'System Info'
$url: { route: ezplatform.systeminfo }
tags:
- { name: ezplatform.menu.item, parent: ezplatform.menu.main.admin, priority: 10 }

ezplatform.menu.main.admin.sections:
class: EzSystems\EzPlatformAdminUi\Menu\Item
arguments:
$identifier: sections
$url: { route: ezplatform.section.list }
tags:
- { name: ezplatform.menu.item, parent: ezplatform.menu.main.admin, priority: 20 }

ezplatform.menu.main.admin.roles:
class: EzSystems\EzPlatformAdminUi\Menu\Item
arguments:
$identifier: roles
$url: { route: ezplatform.role.list }
tags:
- { name: ezplatform.menu.item, parent: ezplatform.menu.main.admin, priority: 30 }

ezplatform.menu.main.admin.languages:
class: EzSystems\EzPlatformAdminUi\Menu\Item
arguments:
$identifier: languages
$url: { route: ezplatform.language.list }
tags:
- { name: ezplatform.menu.item, parent: ezplatform.menu.main.admin, priority: 40 }

ezplatform.menu.main.admin.contenttypes:
class: EzSystems\EzPlatformAdminUi\Menu\Item
arguments:
$identifier: contenttypes
$name: 'Content Types'
$url: { route: ezplatform.content_type_group.list }
tags:
- { name: ezplatform.menu.item, parent: ezplatform.menu.main.admin, priority: 50 }


ezplatform.menu.sidebar:
class: EzSystems\EzPlatformAdminUi\Menu\Menu
arguments:
$identifier: 'sidebar'
tags:
- { name: ezplatform.menu, identifier: sidebar }

ezplatform.menu.sidebar.search:
class: EzSystems\EzPlatformAdminUi\Menu\Item
arguments:
$identifier: search
$enabled: false
tags:
- { name: ezplatform.menu.item, parent: ezplatform.menu.sidebar, priority: 10 }

ezplatform.menu.sidebar.browse:
class: EzSystems\EzPlatformAdminUi\Menu\Item
arguments:
$identifier: browse
tags:
- { name: ezplatform.menu.item, parent: ezplatform.menu.sidebar, priority: 20 }

ezplatform.menu.sidebar.trash:
class: EzSystems\EzPlatformAdminUi\Menu\Item
arguments:
$identifier: trash
$url: { route: ezplatform.trash.list }
tags:
- { name: ezplatform.menu.item, parent: ezplatform.menu.sidebar, priority: 30 }
- { name: knp_menu.menu_builder, method: build, alias: ezplatform_admin_ui.menu.main }
1 change: 1 addition & 0 deletions src/bundle/Resources/config/services/service_aliases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ services:
factory: 'eZ\Publish\API\Repository\Repository:getPermissionResolver'

eZ\Publish\Core\Helper\FieldsGroups\FieldsGroupsList: '@ezpublish.fields_groups.list'
eZ\Publish\Core\MVC\ConfigResolverInterface: '@ezpublish.config.resolver'

# Repository Forms
EzSystems\RepositoryForms\Form\Type\Role\LimitationType: '@ezrepoforms.policy.limitation.form'
Expand Down
2 changes: 1 addition & 1 deletion src/bundle/Resources/views/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</head>
<body class="{% block bodyClass %}{% endblock %}">
{% block navigation %}
{{ knp_menu_render('main', {
{{ knp_menu_render('ezplatform_admin_ui.menu.main', {
'template': '@EzPlatformAdminUi/parts/menu.html.twig',
'currentClass': 'active',
'ancestorClass': 'active'
Expand Down
6 changes: 1 addition & 5 deletions src/bundle/Resources/views/parts/menu.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,5 @@
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/bundles/ezplatformadminui/img/ez-icons.svg#{{ item.extras.icon }}"></use>
</svg>
{% endif %}
{% if options.allow_safe_labels and item.getExtra('safe_label', false) %}
{{ item.label|raw }}
{% else %}
{{ item.label }}
{% endif %}
{{ parent() }}
{% endblock %}
84 changes: 84 additions & 0 deletions src/lib/Menu/AbstractBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?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 EzSystems\EzPlatformAdminUi\Menu\Event\ConfigureMenuEvent;
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

abstract class AbstractBuilder
{
/** @var FactoryInterface */
protected $factory;

/** @var EventDispatcherInterface */
protected $eventDispatcher;

/**
* @param FactoryInterface $factory
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(FactoryInterface $factory, EventDispatcherInterface $eventDispatcher)
{
$this->factory = $factory;
$this->eventDispatcher = $eventDispatcher;
}

/**
* @param string $id
* @param array $options
*
* @return ItemInterface
*/
protected function createMenuItem(string $id, array $options)
{
$defaults = [
'extras' => ['translation_domain' => 'menu'],
];

return $this->factory->createItem($id, array_merge_recursive($defaults, $options));
}

/**
* @param string $name
* @param Event $event
*/
protected function dispatchMenuEvent(string $name, Event $event): void
{
$this->eventDispatcher->dispatch($name, $event);
}

/**
* @param ItemInterface $menu
*
* @return ConfigureMenuEvent
*/
protected function createConfigureMenuEvent(ItemInterface $menu): ConfigureMenuEvent
{
return new ConfigureMenuEvent($this->factory, $menu);
}

/**
* @param array $options
*
* @return ItemInterface
*/
public function build(array $options): ItemInterface
{
$menu = $this->createStructure($options);

$this->dispatchMenuEvent($this->getConfigureEventName(), $this->createConfigureMenuEvent($menu));

return $menu;
}

abstract protected function getConfigureEventName(): string;

abstract protected function createStructure(array $options): ItemInterface;
}
50 changes: 50 additions & 0 deletions src/lib/Menu/Event/ConfigureMenuEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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\Event;

use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\EventDispatcher\Event;

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';

/** @var FactoryInterface */
private $factory;

/** @var ItemInterface */
private $menu;

/**
* @param FactoryInterface $factory
* @param ItemInterface $menu
*/
public function __construct(FactoryInterface $factory, ItemInterface $menu)
{
$this->factory = $factory;
$this->menu = $menu;
}

/**
* @return FactoryInterface
*/
public function getFactory()
{
return $this->factory;
}

/**
* @return ItemInterface
*/
public function getMenu()
{
return $this->menu;
}
}
Loading

0 comments on commit cc0ad6e

Please sign in to comment.