Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Use KnpMenu for the main backend menu #1066

Merged
merged 17 commits into from
Oct 26, 2017

Conversation

sheeep
Copy link
Member

@sheeep sheeep commented Sep 11, 2017

This PR refactors the way the backend menu is created.

  • Check hasAccess on backend modules
  • Remove / Deprecate old methods in Contao\BackendUser
  • Implement getUserNavigation hook
  • A lot of CS stuff

@sheeep sheeep changed the title [WIP ] Use KnpMenu for the main backend menu [WIP] Use KnpMenu for the main backend menu Sep 11, 2017
@leofeyer leofeyer added this to the 4.5.0 milestone Sep 12, 2017
@leofeyer leofeyer changed the title [WIP] Use KnpMenu for the main backend menu [RFC] Use KnpMenu for the main backend menu Sep 12, 2017
use Knp\Menu\ItemInterface;
use Symfony\Component\EventDispatcher\Event;

class BackendMenuEvent extends Event
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can or should we have a universal menu event? Or does such an event class maybe already exist in KnpMenu?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or does such an event class maybe already exist in KnpMenu?

I don't find any such events in either KnpMenu and KnpMenuBundle.

can or should we have a universal menu event?

We probably could. I can't think of any reasons or possibilities for having more than the tree in this event.

@@ -0,0 +1,65 @@
<?php

namespace Contao\CoreBundle\EventListener\BackendMenu;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we really using subnamespaces for event listeners?


public function onBuild(BackendMenuEvent $event)
{
$tree = $event->getTree();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be moved after the if-null condition

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, we don't need to return the tree.

$tree->addChild($node);
}

// Create the child nodes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to refactor this to a method that generates the child.

@@ -40,6 +40,14 @@ services:
tags:
- { name: kernel.event_listener, event: kernel.terminate, method: onKernelTerminate }

contao.listener.backend_menu.legacy_menu_listener:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here with the namespace

{
private $tree;

public function __construct(ItemInterface $tree)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The event should also contain the menu factory, so it does not need to be injected into the listener.

public function render(ItemInterface $item, array $options = [])
{
$lang = [
'skipNavigation' => \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['skipNavigation'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can later be solved with #1072

factory: ["@contao.menu.backend_menu_builder", create]
arguments: ["@request_stack"]
tags:
- { name: knp_menu.menu, alias: backend }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we need this tag, but if then the alias is not useful.

- "@knp_menu.factory"
- "@event_dispatcher"

contao.menu.backend_menu:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to discussion with @sheeep we don't need the menu as a service because of a custom renderer.

Copy link
Member

@aschempp aschempp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but we should wait for #1072

@leofeyer
Copy link
Member

leofeyer commented Oct 25, 2017

I'm done fixing the coding style and switching to the translator. There are, however, there is an issue that needs to be addressed in the be_menu.html.twig template:

OLD

<li class="tl_level_1_group […] AjaxRequest.toggleNavigation( […] '<?= $arrModules['ajaxUrl']; ?> […]

NEW

<li class="tl_level_1_group […] AjaxRequest.toggleNavigation( […] '{{ path('contao_backend') }} […]

Do we no longer need the ajaxUrl parameter?

@leofeyer
Copy link
Member

Never mind, I just realized that the contao_backend route is the Ajax URL.

@leofeyer leofeyer merged commit df66ffd into contao:develop Oct 26, 2017
@leofeyer
Copy link
Member

Thanks a lot @sheeep.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants