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

Use the Knp menu for the back end header menu #860

Merged
merged 8 commits into from
Jan 3, 2020

Conversation

leofeyer
Copy link
Member

@leofeyer leofeyer commented Oct 21, 2019

This PR makes the necessary changes so the back end header menu is built via Knp menu and the debug button can be added in the manager bundle (this was an open TODO).

The PR also "fixes" the back end main menu, which does not adhere to the Knp menu standards and thus is only partially extendable.

TODOs

  • Rework the main menu
  • Fix the existing unit tests
  • Add unit tests for the new classes

@leofeyer leofeyer added this to the 4.9 milestone Oct 21, 2019
@leofeyer leofeyer self-assigned this Oct 21, 2019
@leofeyer leofeyer force-pushed the feature/knp-header-menu branch 3 times, most recently from e105d57 to d13e3ac Compare October 21, 2019 16:10
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.

I think we should keep the back end menu naming as-is, meaning the be_menu.twig and the respective event. And use a new template and a new event name for the be_header_menu, as devs listening to the BACKEND_MENU_BUILD event are for sure not checking the root node name atm.

core-bundle/src/Resources/contao/languages/en/modules.xlf Outdated Show resolved Hide resolved
@leofeyer
Copy link
Member Author

leofeyer commented Oct 22, 2019

I guess you are right, although it is ugly to have two different events for basically the same thing in the same context. But changed in d0b9a00 now.

@leofeyer
Copy link
Member Author

I am still not convinced that using two events is the right thing to do. Also, I doubt that it would cause any problems, because extensions listening to the BACKEND_HEADER_BUILD event in Contao 4.8 (e.g. the manager bundle), will do something like this:

$categoryNode = $event->getTree()->getChild('system');

if (null === $categoryNode) {
    return;
}

And since there is no intersection of child nodes, this should never cause any problems:

Main menu

  • content
  • design
  • accounts
  • system

Header menu

  • alerts
  • preview
  • submenu
  • burger

@contao/developers What do you think? Can we use the same event for both menus?

@ausi
Copy link
Member

ausi commented Oct 23, 2019

If I can differentiate between header and main navigation easily (like $event->getTree()->getName() === 'headerMenu'?) and it doesn’t break existing code I’m in favor of one event.

@Toflar
Copy link
Member

Toflar commented Oct 23, 2019

I'm with @ausi except for the fact that I would like to compare to a class constant rather than a regular string.

@leofeyer
Copy link
Member Author

leofeyer commented Oct 23, 2019

like $event->getTree()->getName() === 'headerMenu'?

Exactly like this. But in Yoda style. 😂

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.

The changes in the config.php files across all bundles are also not related to this PR at all. Maybe you can create a separate one (according to what we just discussed yesterday) to change that across all bundles. I'm not sure about the implications, but we should discuss that in the separate PR.

@leofeyer
Copy link
Member Author

Of course they are related to this PR. The PR reworks the back end menus and the config.php changes affect the menu item order.

Copy link
Member

@Toflar Toflar left a comment

Choose a reason for hiding this comment

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

Neat work here! Well done! I have my concerns regarding BC breaks and added them as comments so we can discuss. Otherwise this PR is in a good shape 👍

core-bundle/src/EventListener/BackendMenuListener.php Outdated Show resolved Hide resolved
core-bundle/src/Menu/BackendMenuBuilder.php Outdated Show resolved Hide resolved
core-bundle/src/Routing/PreviewUrlGenerator.php Outdated Show resolved Hide resolved
Copy link
Member

@Toflar Toflar left a comment

Choose a reason for hiding this comment

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

As stated in inline comments, this currently introduces unnessary BC breaks which could be nicely solved using separate listeners for the menu items, just like it's done e.g. for the debug link in the manager-bundle.

@leofeyer
Copy link
Member Author

I ask myself why it builds the previewUrl, the logoutUrl and then dispatches the event?

The menu builder does not build these URLs – the injected generators do.

BC breaks which could be nicely solved using separate listeners for the menu items, just like it's done e.g. for the debug link in the manager-bundle.

I disagree. The manager bundle uses an event listener, because that is the only way for other bundles to add menu links.

There is no point in using separate event listeners except for keeping the constructor arguments the way they are now. Other than that, it is just more complicated and more confusing for anyone who needs to work with it.

@aschempp
Copy link
Member

I kinda agree with @Toflar. The builder is responsible for providing an event to build the menu, not to actually build the menu. That's what the event listeners are for. If the core menu items are not added by an event listener, I can't use priorities to be before/after that listener.

@aschempp aschempp requested review from aschempp and removed request for aschempp November 25, 2019 16:28
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.

Still standing by my statement (this is to shut up PR reminders 😂 )

@leofeyer
Copy link
Member Author

I have extracted the main menu changes into a separate PR: #1101

@leofeyer leofeyer changed the base branch from master to feature/knp-header-menu-1 December 16, 2019 14:44
@leofeyer leofeyer changed the base branch from feature/knp-header-menu-1 to master December 18, 2019 10:29
@leofeyer
Copy link
Member Author

The PR has been rebased and changed according to what we have discussed. Please review again. 😊

Toflar
Toflar previously approved these changes Dec 18, 2019
Copy link
Member

@Toflar Toflar left a comment

Choose a reason for hiding this comment

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

So much cleaner now, with proper responsibilities! I like this 😄 👍
Should have more than one PR approval here before merge though.

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.

Generally looks good. I think there's one optimization possible:
Same as the debug button, the preview and logout button should be added in their own menu listener. These service listener should contain the code from PreviewUrlGenerator and LogoutUrlGenerator, because the url generators don't make much sense to me. They're never being reused, they are solely for the purpose of generating that button. It would also make DI for the regular menu builder much simpler, because it wouldn't contain multiple services only needed for one button each.


$buger = $factory
->createItem('burger')
->setLabel('<button type="button" id="burger"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12h18M3 6h18M3 18h18"/></svg></button>')
Copy link
Member

Choose a reason for hiding this comment

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

The button should have a label or title, so we should probably not remove MSC.burgerTitle

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so, because the button is only visible on mobile devices and neither title nor label would be shown.

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 assume it is visible to screen readers, and most likely to an iPhone screen reader as well

@leofeyer
Copy link
Member Author

leofeyer commented Dec 20, 2019

It would also make DI for the regular menu builder much simpler, because it wouldn't contain multiple services only needed for one button each.

The services do not generate the buttons but only their URLs. This means whenever you want to generate the logout URL or the preview URL, you can use the service.

As soon as #989 is merged, we can reuse the preview URL service in the tl_page DCA to generate the URLs for the direct links (when you click the icon on the left).

@aschempp
Copy link
Member

This means whenever you want to generate the logout URL or the preview URL, you can use the service.

As soon as #989 is merged, we can reuse the preview URL service in the tl_page DCA to generate the URLs for the direct links (when you click the icon on the left).

No you cannot. The service is explicitly bound to the CURRENT_ID and only works for exactly that button use case. That's what I mean, there's never a case for using that service standalone. You can't pass the current page ID or thelike.

@leofeyer
Copy link
Member Author

I have implemented the requested changes. Please review again.

Toflar
Toflar previously approved these changes Dec 23, 2019
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.

Looks very good now to me! Just a few minor notes 👍

@leofeyer leofeyer merged commit 2aeda7f into master Jan 3, 2020
@leofeyer leofeyer deleted the feature/knp-header-menu branch January 3, 2020 11:31
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.

None yet

5 participants