Currently menu links are basically point to a certain path, but in a world, in which drupal could alter its own internal paths,
we should rather store the route names and the parameters which together can build a link/url using the url generator.

API Changes

  • Add a new database column to {menu_links} store route parameters
  • Add handing for loading this new data
  • Adds handling for parsing and saving the parameters derived from the path when saving a menu link
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Issue tags: +MenuSystemRevamp

Add tag.

pwolanin’s picture

Yes, we should use e.g. href only for an external link and maybe store a route name + params also.

amateescu’s picture

Component: menu system » menu_link.module

We already store the route names (yes, the one you want to remove in #2021779-10: Decouple shortcuts from menu links :) ). I'm wondering how will this impact the ability to create hierarchies.

dawehner’s picture

Isn't the menu hierarchy (at least in theory) based upon menu link IDs instead of paths?

amateescu’s picture

It is, in theory and practice :) But when you don't specify a parent, it will try to find it based on the path.

pwolanin’s picture

@amateescu - I think if we create the now hook_menu_links, we should make you specify the parent using a machine name of some sort.

amateescu’s picture

That would remove a lot of complexity from our current code, so I'm definitely +1 on having to specify the parent.

Wih that being said, I have another proposal. How about doing this "route name + parameters" work in the link.module (the link field doesn't support internal paths atm) and then just switch menu links to use it? This was also one my original goals in the menu link entity conversion, to be able to leverage the field system and drop a lot of custom code.

Edit: The thing is.. if we don't do this alternative approach, contrib would have to do it anyway, and it will probably just copy the code from menu links.

pwolanin’s picture

Ok, interesting - yes that sounds like something we should consider - but the problem with this format it that you can interchange it with actual URLs.

amateescu’s picture

Crossposting the issue about adding internal paths support to core's link.module: #2054011: Implement built-in support for internal URLs

dawehner’s picture

I am wondering whether using a different implementation on the ground would force it to be an API change?

dawehner’s picture

Status: Active » Needs review
FileSize
3.82 KB
3.82 KB

So here is a patch which automatically adds the route parameters to the menu_links table.
This information is not used to provide menu links due to multiple reasons:

  • We need the options on the url generator
  • Menu link will still be changed to EntityNG so let's not make things harder
pwolanin’s picture

I think we need some more fundamental reworking of this to start getting rid of path-based data except for parsing user input? Maybe also move to hook_menu_link()

Also - I thought this was using the link field type?

Status: Needs review » Needs work

The last submitted patch, menu_link-2051889-11.patch, failed testing.

dawehner’s picture

I think we need some more fundamental reworking of this to start getting rid of path-based data except for parsing user input? Maybe also move to hook_menu_link()

That is for sure right, but we simply can't do that in one issue, especially we kind of have to wait until the EntityNG conversion is done. What about getting this patch in, then have one issue which introduces some functionality to get menu links rendered via the url generator (the link generator patch would really help in that regard).

We can't remove functionality yet, as there are still classical non converted hook_menu entries.

dawehner’s picture

Status: Needs work » Needs review
FileSize
732 bytes
4.53 KB

This should fix most of the errors. Based upon my last comment I think this patch is big enough to make a small step forward.

dawehner’s picture

FileSize
7.43 KB

Added some testcoverage.

amateescu’s picture

+++ b/core/modules/menu_link/menu_link.install
@@ -202,6 +202,13 @@ function menu_link_schema() {
+        'serialize' => TRUE,

Where is this unserialized? Either I'm not seeing it, or we're missing tests that we're not actually using this new property.

dawehner’s picture

FileSize
2.34 KB
9.77 KB

Good catch! Ensured that by adding a test.

pwolanin’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community

Yes, this is essential to have - storing a route name doesn't make sense if you don't have parameters for a route with path slugs

catch’s picture

Status: Reviewed & tested by the community » Needs review
  1. +++ b/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php
    @@ -485,7 +492,13 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
    +      if ($result = $this::findRouteNameParameters($this->link_path)) {
    

    I realise this is mostly just moved code, but shouldn't it be static::findRouteNameParameters() instead of $this::?

  2. +++ b/core/modules/system/system.install
    @@ -2242,6 +2242,21 @@ function system_update_8059() {
    +function system_update_8060() {
    

    No upgrade path for existing menu links?

pwolanin’s picture

@catch - what's wrong with the update function?

+  db_add_field('menu_links', 'route_parameters', $spec);
amateescu’s picture

@catch, afaik, we don't support HEAD2HEAD updates yet.

dawehner’s picture

FileSize
9.72 KB

Rerolled and fixed point one of catch.

Opened a follow up for number 2: #2070191: Convert the url to route_name and route_parameters for existing menu links

Status: Needs review » Needs work

The last submitted patch, menu_link-2051889-23.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
Issue tags: +PHPUnit
FileSize
767 bytes
9.71 KB

The menu link test have to be adapted as well.

pwolanin’s picture

Status: Needs review » Needs work

ugh - what is that method even doing on the entity class?

At this point we should make it protected and not expose it at least - there is way too much dependence on the old router system in this entity.

pwolanin’s picture

Title: Add a parameters property to menu links » Add route parameters and machine name properties to menu links

We should also add a field for a machine name - I'm not sure why we even have the uuid?

pwolanin’s picture

FileSize
9.83 KB

something more like this as a basis for moving forward?

catch’s picture

@amateescu I mean the Drupal 7 to Drupal 8 upgrade path. At the moment it looks like this will be empty until the menu link gets resaved, then it might get populated. Maybe that is the upgrade path but there's no mention of it either in the issue or the patch.

pwolanin’s picture

hmm, it's unclear to me that we need to save the machine name to the DB, so maybe that was premature. Still, I don't even see how it's currently possible to build a link based on a route name and parameters, which should be the most natural code path in the final version?

pwolanin’s picture

ok, maybe adding the machine name here is overkill - but I still think we should be hiding the lookup code - ideally we won't need it at all in the long-run except when processing user-entered paths

pwolanin’s picture

Status: Needs work » Needs review
FileSize
941 bytes
9.77 KB

ok, well there is a ton of cleanup and follow-up work to do for menu links, but we can't even start without the parameters.

So, let's go back to the patch in #25. This is the same modulo some minor doxygen fixes.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

These small doxygen fixes are fine.

tstoeckler’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
650 bytes
10.26 KB
+++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkInterface.php
@@ -56,13 +56,14 @@ public function reset();
+   *   attay if no route was matched.

What's an attay? :-)

pwolanin’s picture

Title: Add route parameters and machine name properties to menu links » Add route parameters property to menu links
Status: Needs review » Reviewed & tested by the community

attay == symptom of my bad typing skills...

We really need to get this in a basis for rendering route-based links

pwolanin’s picture

Issue tags: -PHPUnit, -MenuSystemRevamp

Status: Reviewed & tested by the community » Needs work

The last submitted patch, menu_link_parameters-2051889-34.patch, failed testing.

pwolanin’s picture

Status: Needs work » Needs review
Issue tags: +PHPUnit, +MenuSystemRevamp
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC

pwolanin’s picture

alexpott’s picture

Title: Add route parameters property to menu links » Change notice: Add route parameters property to menu links
Priority: Major » Critical
Status: Reviewed & tested by the community » Active
Issue tags: +API change, +Needs change record, +Approved API change

Committed 28f1ad6 and pushed to 8.x. Thanks!

We need to ensure https://drupal.org/node/1914008 is up-to-date.

dawehner’s picture

Status: Active » Needs review
pwolanin’s picture

Title: Change notice: Add route parameters property to menu links » Add route parameters property to menu links
Status: Needs review » Fixed

Looks fine - will have some more changes that need doc before release in any case

Berdir’s picture

Priority: Critical » Major
Issue tags: -Needs change record

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.