-
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-28117: Created new main menu builder with extensibility point
- Loading branch information
Showing
10 changed files
with
323 additions
and
127 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/bundle/DependencyInjection/Configuration/Parser/LocationIds.php
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,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] | ||
); | ||
} | ||
} | ||
} |
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,4 @@ | ||
parameters: | ||
ezsettings.default.location_ids.content: 2 | ||
ezsettings.default.location_ids.media: 43 | ||
ezsettings.default.location_ids.users: 5 |
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
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,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; | ||
} |
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,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; | ||
} | ||
} |
Oops, something went wrong.