diff --git a/src/bundle/DependencyInjection/Configuration/Parser/LocationIds.php b/src/bundle/DependencyInjection/Configuration/Parser/LocationIds.php new file mode 100644 index 0000000000..4112e01812 --- /dev/null +++ b/src/bundle/DependencyInjection/Configuration/Parser/LocationIds.php @@ -0,0 +1,54 @@ + + */ + 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] + ); + } + } +} diff --git a/src/bundle/EzPlatformAdminUiBundle.php b/src/bundle/EzPlatformAdminUiBundle.php index 480df7b216..1b3808766c 100644 --- a/src/bundle/EzPlatformAdminUiBundle.php +++ b/src/bundle/EzPlatformAdminUiBundle.php @@ -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; @@ -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); } diff --git a/src/bundle/Resources/config/ezpublish_default_settings.yml b/src/bundle/Resources/config/ezpublish_default_settings.yml new file mode 100644 index 0000000000..fc9c2f2cf5 --- /dev/null +++ b/src/bundle/Resources/config/ezpublish_default_settings.yml @@ -0,0 +1,4 @@ +parameters: + ezsettings.default.location_ids.content: 2 + ezsettings.default.location_ids.media: 43 + ezsettings.default.location_ids.users: 5 diff --git a/src/bundle/Resources/config/services/menu.yml b/src/bundle/Resources/config/services/menu.yml index 4adad141f0..2ce769c15c 100644 --- a/src/bundle/Resources/config/services/menu.yml +++ b/src/bundle/Resources/config/services/menu.yml @@ -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 } diff --git a/src/bundle/Resources/config/services/service_aliases.yml b/src/bundle/Resources/config/services/service_aliases.yml index 081e7ce2ba..df39e79aec 100644 --- a/src/bundle/Resources/config/services/service_aliases.yml +++ b/src/bundle/Resources/config/services/service_aliases.yml @@ -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' diff --git a/src/bundle/Resources/views/layout.html.twig b/src/bundle/Resources/views/layout.html.twig index 1cf8077efc..49f8b0d4a7 100644 --- a/src/bundle/Resources/views/layout.html.twig +++ b/src/bundle/Resources/views/layout.html.twig @@ -35,7 +35,7 @@
{% block navigation %} - {{ knp_menu_render('main', { + {{ knp_menu_render('ezplatform_admin_ui.menu.main', { 'template': '@EzPlatformAdminUi/parts/menu.html.twig', 'currentClass': 'active', 'ancestorClass': 'active' diff --git a/src/bundle/Resources/views/parts/menu.html.twig b/src/bundle/Resources/views/parts/menu.html.twig index 8951a68283..2b8665d9ab 100644 --- a/src/bundle/Resources/views/parts/menu.html.twig +++ b/src/bundle/Resources/views/parts/menu.html.twig @@ -137,9 +137,5 @@ {% endif %} - {% if options.allow_safe_labels and item.getExtra('safe_label', false) %} - {{ item.label|raw }} - {% else %} - {{ item.label }} - {% endif %} + {{ parent() }} {% endblock %} diff --git a/src/lib/Menu/AbstractBuilder.php b/src/lib/Menu/AbstractBuilder.php new file mode 100644 index 0000000000..aa3d34a4f5 --- /dev/null +++ b/src/lib/Menu/AbstractBuilder.php @@ -0,0 +1,84 @@ +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; +} diff --git a/src/lib/Menu/Event/ConfigureMenuEvent.php b/src/lib/Menu/Event/ConfigureMenuEvent.php new file mode 100644 index 0000000000..c57948f77a --- /dev/null +++ b/src/lib/Menu/Event/ConfigureMenuEvent.php @@ -0,0 +1,50 @@ +factory = $factory; + $this->menu = $menu; + } + + /** + * @return FactoryInterface + */ + public function getFactory() + { + return $this->factory; + } + + /** + * @return ItemInterface + */ + public function getMenu() + { + return $this->menu; + } +} diff --git a/src/lib/Menu/MainMenuBuilder.php b/src/lib/Menu/MainMenuBuilder.php new file mode 100644 index 0000000000..110fdb17b7 --- /dev/null +++ b/src/lib/Menu/MainMenuBuilder.php @@ -0,0 +1,119 @@ +configResolver = $configResolver; + } + + protected function getConfigureEventName(): string + { + return ConfigureMenuEvent::MAIN_MENU; + } + + /** + * @param array $options + * + * @return ItemInterface + * + * @throws InvalidArgumentException + */ + public function createStructure(array $options): ItemInterface + { + $menu = $this->factory->createItem('root'); + + $menu->addChild($this->createMenuItem('main__content', ['extras' => ['icon' => 'content-list']])); + $menu->addChild($this->createMenuItem('main__admin', ['extras' => ['icon' => 'panel']])); + + $menu['main__content']->addChild( + $this->createMenuItem('main__content__content_structure', [ + 'route' => '_ezpublishLocation', + 'routeParameters' => [ + 'locationId' => $this->configResolver->getParameter('location_ids.content'), + ], + ]) + ); + $menu['main__content']->addChild( + $this->createMenuItem('main__content__media', [ + 'route' => '_ezpublishLocation', + 'routeParameters' => [ + 'locationId' => $this->configResolver->getParameter('location_ids.media'), + ], + ]) + ); + + $menu['main__admin']->addChild( + $this->createMenuItem('main__admin__systeminfo', ['route' => 'ezplatform.systeminfo']) + ); + $menu['main__admin']->addChild( + $this->createMenuItem('main__admin__sections', ['route' => 'ezplatform.section.list']) + ); + $menu['main__admin']->addChild( + $this->createMenuItem('main__admin__roles', ['route' => 'ezplatform.role.list']) + ); + $menu['main__admin']->addChild( + $this->createMenuItem('main__admin__languages', ['route' => 'ezplatform.language.list']) + ); + $menu['main__admin']->addChild( + $this->createMenuItem('main__admin__content_types', ['route' => 'ezplatform.content_type_group.list']) + ); + $menu['main__admin']->addChild( + $this->createMenuItem('main__admin__users', [ + 'route' => '_ezpublishLocation', + 'routeParameters' => [ + 'locationId' => $this->configResolver->getParameter('location_ids.users'), + ], + ]) + ); + + return $menu; + } + + /** + * @return array + */ + public static function getTranslationMessages(): array + { + return [ + (new Message('main__content', 'menu'))->setDesc('Content'), + (new Message('main__content__content_structure', 'menu'))->setDesc('Content structure'), + (new Message('main__content__media', 'menu'))->setDesc('Media'), + (new Message('main__admin', 'menu'))->setDesc('Admin'), + (new Message('main__admin__systeminfo', 'menu'))->setDesc('System Information'), + (new Message('main__admin__sections', 'menu'))->setDesc('Sections'), + (new Message('main__admin__roles', 'menu'))->setDesc('Roles'), + (new Message('main__admin__languages', 'menu'))->setDesc('Languages'), + (new Message('main__admin__content_types', 'menu'))->setDesc('Content Types'), + (new Message('main__admin__users', 'menu'))->setDesc('Users'), + ]; + } +}