Updated: Comment #N

Problem/Motivation

Menu links have two base fields ('menu_name' and 'bundle'). Both fields are same in our implementation. We need to distinguish both fields for fieldable entities. But there are other problems besides that, the missing bundle column in our database schema for {menu_link} breaks the bundle condition in EntityQuery (look at the attached test).

Proposed resolution

Add bundle column to menu_link schema.

Remaining tasks

Review

User interface changes

None

API changes

None

Original report by @username

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

webflo’s picture

Issue summary: View changes
FileSize
964 bytes
2.41 KB
webflo’s picture

Title: Store menu link bundle » Store menu link bundle, fix EntityQuery for menu links

The last submitted patch, store-menu-link-bundle.patch, failed testing.

dawehner’s picture

Assigned: Unassigned » amateescu

Let's assign to the only one who really knows about this kind of stuff.

The last submitted patch, 1: store-menu-link-bundle-2177611-1-test-only.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 1: store-menu-link-bundle-2177611-1.patch, failed testing.

amateescu’s picture

The 'bundle' property for menu links was added in #1966298: Introduce menu link bundles per menus (a patch that I still don't agree with :)) and it's not something that should be stored or queried. It's actually a 'computed' field, but not marked as such since menu links are not yet converted to the new API.

That said, we should actually just remove it and set the 'bundle' entity key for menu links to 'menu_name' in menu_entity_info_alter(). Not sure why it wasn't done like this in the first place...

webflo’s picture

FileSize
2.46 KB

Like this?

amateescu’s picture

Status: Needs work » Needs review

Yup :)

Berdir’s picture

+++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php
@@ -692,6 +692,25 @@ public function testMenuParentsJsAccess() {
+      ->condition($entity_info->getBundleKey('bundle'), 'tools');

You want getKey(), bundle_keys defines how the keys are named on the bundle objects, e.g. node_type.

It's used 3 times in core, only one of those is correct (field_extract_bundle()), and that is no longer used, so we should drop it completely.

That said, I don't really get the menu_link bundle/menu_name stuff either :)

webflo’s picture

FileSize
2.45 KB

You are right.

Berdir’s picture

Created #2177971: Remove bundle_keys annotation and related methods ( thanks for reminding me), that should be a fun patch to write :)

dawehner’s picture

Given that both amateescu and berdir are okay with the approach.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Given that both amateescu and berdir are okay with the approach.

Berdir’s picture

For the record, what I meant is "I have no clue if this is correct" :)

This was discussed for a looong time....

amateescu’s picture

The whole bundle workaround was done this way so we don't make 'menu_name' the official bundle key for this entity type (based on my objections in the issue linked in #7), but it's clear that it can get confusing when you try to use EntityQuery with that 'computed' property..

I'm not really sure how to proceed here. While I still think that menus should not act as bundles for menu links, it seems that pretty much everyone else doesn't agree with that, so I'll have to go with the flow.

What would help here would be to make the bundle() method return $this->{$this->entityInfo()->getKey('bundle')};, so contrib can easily override the bundle key and not replace the MenuLink class entirely.

Berdir’s picture

@amateescu: ContentEntityBase should take care of that,

tstoeckler’s picture

So IIRC the use-case for differentiating between menu name and bundle was that you could have menu links from different bundles in one menu. Because field instances are per-bundle, this would allow to attach an image field only to second-level menu links in a menu tree, for example. Also both book and shortcut module used to use that functionality in some way which I can't remember right now.

I don't see why we can't just store menu_name and bundle separately. The default implementation that if 'bundle' is not set, then 'bundle' == 'menu_name' can stay, but then we can leave the flexibility in place for people that need it.

And if we decide that there should not even be that relation then we simply remove that default initialization. (If I understand him correctly, that is @amateescu's position?!)

Xano’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
2.37 KB

Re-roll.

tstoeckler’s picture

Priority: Normal » Major
Issue tags: +entity API, +multilingual

So this is at least major as a) menu links are a central aspect of Drupal and entity queries not working for them is pretty bad and b) we need to figure out what to do here in order for menu links to be usable in the real world during D8 cycle.

I just looked at some of the original issues and also the current implementations of menu link bundles. Since shortcuts are no longer menu links they are no longer relevant to this discussion. book.module, however, still manages a single bundle for all it's book links across multiple menus. The fact that it does that, however, is completely unused. So that part would need to be removed from the patch as well.

Basically we need to decide what to do here. I'll try to summarize the options once again in oder to try and bring this forward a bit:

A) $menu_name === $bundle

This is the intuitive concept for menu link bundles. Bundles separate entities of the same type from another and in reality menu links are mostly separated from each other by a different menu name.

Two use-cases are not supported with this however:

1) Many menus, one bundle: As changing bundles of entities is not something we generally support, A) means that you cannot move menu links between menus. Having menu links from menus have the same bundle would allow moving menu links between those links willy-nilly.

2) One menu, many bundles: If you have fieldable menu links, it might only make sense to be able to attach fields to a certain level in your menu, i.e. to your top-level menu links but not the second-level ones. Since field instances and entity displays are per-bundle it is not possible to have those differ between multiple links in one menu if they are all the same bundle.

B) $bundle != $menu_name

This would allow a great amount of flexibility including the use-cases described above. As it is currently implemented, we could keep the behavior of making the bundle the menu name by default, if no other bundle is set. That would allow contrib UIs to go crazy with A1) and A2). I'm not aware of any performance problems with this but (perhaps, arguably) this increases the maintenance and complexity burden of menu links.

Personally I certainly think the use-cases in A1) and A2) are pretty valid so I would tentatively pick B), but I'm not bent on that very much. I just think we need to do *something* here. If we want #11 (which is sort of A)) and not #1 (which is sort of B)) I would not block that in any way.

webflo’s picture

Issue tags: +SprintWeekend2014, +D8MA
Berdir’s picture

Just a quick note on the book topic, haven't read everything yet. #2084421: Phase 2 - Decouple book module schema from menu links will mean that book will no longer (mis-)use menu links directly, and that's a beta blocker.

amateescu’s picture

@tstoeckler, thanks for the in-depth writeup. As I mentioned before, I'm still very much in favor of #20 B), and if that means we'll have duplicate data in the 'bundle' and 'menu_name' columns of the menu_links table, so be it :)

xjm’s picture

19: drupal_2177611_19.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 19: drupal_2177611_19.patch, failed testing.

xjm’s picture

pwolanin’s picture

Status: Needs work » Postponed

Yes, please postpone.

amateescu’s picture

Assigned: amateescu » Unassigned
mgifford’s picture

dawehner’s picture

Add bundle column to menu_link schema.

We have a bundle column, though it defaults to 'menu_link_content' always currently.

catch’s picture

Title: Store menu link bundle, fix EntityQuery for menu links » Check test coverage for menu link content entities with entity query
Priority: Major » Normal
Issue tags: +Needs reroll

That probably means the bug has been fixed, we should just check the test coverage in HEAD covers what's in the patch here.

catch’s picture

Category: Bug report » Task

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

vacho’s picture

The structure change completely for this feature. Module "menu_link" it does not exist anymore it replaced by "menu_link_content" with other logic and covered with several tests. So I think this patch can't be rerolled

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
pooja saraah’s picture

Status: Needs work » Needs review
FileSize
544 bytes

Applied patch against 9.3.x

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Medha Kumari’s picture

Rerolled the patch #45 with Drupal 9.5.x and 10.1.x.

smustgrave’s picture

Version: 9.4.x-dev » 10.1.x-dev
Status: Needs review » Postponed (maintainer needs more info)
Issue tags: +Needs Review Queue Initiative

This issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 200, following Review a patch or merge require as a guide.

As #40 mentioned I don't think this can be rerolled.

Is the reported issue still an problem in D10 with the menu_link_content module?

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

If still a valid task please reopen updating issue summary for D10.

Thanks.