Problem/Motivation
Upgrading to latest version 3.0.4 is breaking menus in our multilanguage site. Problem stems from the latest update hook taxonomy_menu_ui_update_9001 where update hook is renaming menu bundle to be the same as menu name. In our case bundle for all our menus is always "menu_link_content" since we are using core module with the same name which will preset the bundle name as "menu_link_content": https://git.drupalcode.org/project/drupal/-/blob/10.4.x/core/modules/men...
Steps to reproduce
- Enable menu_link_content module and taxonomy_menu_ui (3.0.3 before latest change introduced)
- Create a new menu and add a menu link
- Update module taxonomy_menu_ui to the latest 3.0.4
Proposed resolution
I don't fully know the background and the reason for this change. Let me know if more info or help is needed.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | 3501383-24.patch | 912 bytes | r-mo |
| #22 | 3501383-22.patch | 890 bytes | lobodakyrylo |
| #14 | 3501383-14.patch | 576 bytes | robertom |
| #8 | taxonomy_menu_ui-menu_bundle_name-3501383-8.patch | 1.27 KB | dewalt |
| #7 | 3501383-7.patch | 729 bytes | jaroslav červený |
Issue fork taxonomy_menu_ui-3501383
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
lobodakyrylo commentedSome time ago, Drupal Core added a bundle field to content menu items, and by default, it's always the same as the menu name. Unfortunately, no one noticed that, and the module created menu items without a bundle, and the core changed the bundle with the "menu_link_content" which is the entity name. Because of that, you can't translate menu items. If your menu is "main_menu", and you set translation for that, the core identifies menu items you created via this module as "menu_link_content" and this bundle doesn't have translation settings. To solve this, all the bundles should be the same as the menu names. This update did this.
I couldn't reproduce this issue you experienced, please provide more information about your menu names, menu items, and maybe screenshots what happened after update.
Comment #3
alexander tallqvist commentedWe are experiencing the same issue on our multilingual Drupal site running Drupal 10.3.11.
Default language: Finnish (FI)
Translated languages: English (EN) and Swedish (SV)
Issue Details
After applying the latest version of
taxonomy_menu_uiand running database updates, we encountered the following problems:1. Fatal Error When Editing or Unpublishing Translated Nodes
Attempting to edit or unpublish a translated version of a node (SV or EN) results in a fatal error when saving:
2. Menu Link Text Overwritten After Fatal Error
After triggering the fatal error, the menu link text of the original (FI) translation is overwritten with the text from the edited translation.
Example:
Original FI node menu link text: "Hei maailma!"
Translated EN node menu link text: "Hello world!"
If we attempt to unpublish the EN version, the fatal error occurs.
After this, the FI node's menu text changes to "Hello world!" instead of staying as "Hei maailma!".
Potential fix
Adding the following update hook to a module and running database updates seems to fix the issue for use:
Comment #4
lobodakyrylo commentedIt happened because the menu name was previously used to get to the menu to which the link belonged. Later, the bundle field was defined for this purpose, and the menu name field is a rudiment field now. We didn't notice it in time, so you have the bundle field empty for menu items that were created by this module or by other modules. So if you have several menus, for example, header, and footer, then all menu items for the header will have bundle and menu name field as "header" and "footer" for footer.
For me, the menu_link_content bundle is incorrect since it doesn't belong to any menu. I'm curious how you created translation for menus that don't have a bundle since you can't create a translation configuration for that.
Comment #5
mydot commentedFor me the same error. After Taxonomy menu UI module update i can not update existing node translations with menu link. When i try to modify the menu item from the menu configuration i get error:
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "entity:menu_link_content:main" plugin does not exist. Valid plugin IDs for Drupal\Core\TypedData\TypedDataManager are: ... entity_revision:menu_link_content, entity_revision:menu_link_content:menu_link_content, ... entity:menu_link_content, entity:menu_link_content:menu_link_content, ... in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 53 of /core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).
i use Taxonomy menu UI 3.0.5 with Drupal 11.1.3
Comment #6
lobodakyrylo commentedIt seems that the menu module sometimes uses the menu name for bundle and sometimes the menu_link_content value. I'm not sure what's going on there, but it looks like a major issue for now. I can't reproduce it on my side since all my websites that use this module had a smooth transition to the new version.
It'd be good if someone gave me the configuration files and composer.json that you use.
Comment #7
jaroslav červený commentedI tested the hook update and it helped.
Comment #8
dewalt commentedI have the same issue with error on menu item edit:
Thanks Jaroslav, the patch is working for existing menu items. I've extended it to avoid the issue with new created ones. Bundle isn't needed to be specified due https://www.drupal.org/project/drupal/issues/2350915.
Kyrylo, I see you've tried to add translations support here - https://git.drupalcode.org/project/taxonomy_menu_ui/-/commit/ae60c128775.... I have no idea how setting the bundle field should help, please look "_menu_ui_node_save()" for example. The main idea is:
- If link exist and it is a translation of existing link - create it with
$entity->addTranslation($term->language()->getId(), $data);- If link is new, please ensure that the link langcode matches with term langcode:
$entity->set('langcode', $term->language()->getId());Comment #11
shivam_tiwari commentedI faced same issue after updating taxonomy_menu_ui module to the latest version. I checked patches added here. #8 patch fixed issue for me. I created MR so we can run test and merge this update to the latest versions.
Thanks
Comment #12
banoodle commentedConfirming the mr fixes the problem introduced by update 9001.
The site I experienced this problem on uses translation and we didn't have any blank bundles in the menu_link_content_data table and everything was working fine until we attempted to upgrade from 3.0.3 to 3.0.5 of this module.
Update 9001 made the translation settings and a custom field we added on menu links vanish from the UI and front-end.
Comment #13
lobodakyrylo commentedMerge request #6 is completely wrong even though it solves your problem. The bundle field should contain the same as menu_name because if you enable translations for the menu, you will not be able to translate menu items. Translation settings correspond to the bundle name and if they do not fit, then by default the translation is disabled. Let's say you have a menu "Header", then you want to translate it. You go to settings and enable translation for them. But if you try to translate its menu items, their bundle will be menu_link_content not header and Drupal will not allow you to translate them. Read comment #4.
I couldn't reproduce this when Drupal creates a menu item with the menu_link_content bundle. It may happen in the previous versions of Drupal when it added the bundle field but the current structure requires to have bundle the same as menu_name. The menu_item field still exists and as I understand it's a rudiment and will be deleted in the future.
If you can reproduce the menu_link_content bundle from a fresh install, then tell me how to do it.
Comment #14
robertom commentedHi @lobodakyrylo, what version of drupal are you using?
I just installed this module, but with Drupal 10.4.6 I can make it work correctly (with translations) only by using the attached patch (it is the same one present in the MR, but without taxonomy_menu_ui_update_9002() )
To see how Drupal behaves by default I performed the following steps:
checking the database I see that both table "menu_link_content" and table "menu_link_content_data" have bundle values as "menu_link_content"
By installing the taxonomy_menu_ui module and applying the patch, I can correctly insert and translate menu items from the taxonomy term edit form.
Searching through the core issues, I found these two that go in the direction of keeping the bundle at menu_link_content, but none where it is specified to use the bundle equal to the menu_name
Comment #15
tom_ek commentedI can confirm that the patch from #8 fixes the issue.
Basically when the menu item is saved, the entity validator tries to load the proper TypedData for the entity type and bundle. But menu_link_content has only one valid bundle, and that's menu_link_content. Passing menu name there will always trigger the error. I had it when saving any menu item after the hook_update_9001.
Basically menu_tree table is for the menu structure.
As @dewalt mentioned - I also don't think adding the menu name as the bundle could help with the translation. But might be I am missign something?
@kyrylo:
Here's where the bundle is set:
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/menu_...
It's in the MenuLinkContent entity.
Comes from this ticket: https://www.drupal.org/project/drupal/issues/2923429
Comment #16
lobodakyrylo commented@tom_ek I can’t reproduce the issue on fresh Drupal 11 install. It always saves menu name into bundle field. Also, if I enable menu translation, it only works if bundle contains menu name. If bundle will be menu_link_content, you will never have the ability to translate menu links.
Comment #17
nagy.balint commentedJust to report that I got this same issue yesterday on a site that we are maintaining for a long time.
"The "entity:menu_link_content:main" plugin does not exist. "
So the issue definitely happens often (at least on existing sites).
Comment #18
nagy.balint commentedIn fact #8 not only fixed the issue, but also brought back the translate option in the menu admin (/admin/structure/menu/manage/main) which was missing after the module upgrade.
So it actually made it translatable again.
Comment #19
lobodakyrylo commentedComment #21
dewalt commented@lobodakyrylo I see you've found a proper solution (Git link), but why isn’t the commit linked to the ticket?
Also, an important point – what about giving credit to the people who found and described the bug, conducted the analysis, etc.? It doesn’t look good on your part.
Comment #22
lobodakyrylo commented@dewalt good point. This is a patch that should be tested. It reverts changes from the previous update. I also pushed it to dev branch.
Comment #23
jsutta commentedApplied the patch in #22 against a fresh copy of our database without either this patch or the one in https://www.drupal.org/project/taxonomy_menu_ui/issues/3535088. It worked! @lobodakyrylo, thank you for jumping on this!
Comment #24
r-mo commentedUpdate hook in #22 is missing $entity->save() so wasn't updating any broken entities in our existing install. Attached a patch to fix.
Comment #26
lobodakyrylo commented@r-mo good point. I pushed changes to dev.
Comment #27
ronaldmulero commentedThanks @r-mo #24 works for me to fix WSOD when saving "Edit menu link"
taxonomy_menu_ui 3.0.6
Comment #28
jcandan commentedComment #29
lobodakyrylo commentedThe fix has already been committed to the 3.0.x branch and included in the latest release.
The update hook now correctly restores the menu link bundle and saves the affected entities.
Thanks everyone for testing and confirming the fix.