Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The menu items lack the langcode, which is required in order to tell if the given item has a translation in the requested language or not.
Proposed resolution
Add the langcode where possible.
Comment | File | Size | Author |
---|---|---|---|
#22 | 3192576-22.patch | 2.44 KB | andrewbelcher |
#6 | 3192576-6.patch | 1.42 KB | Pooja Ganjage |
#4 | 3192576-4.patch | 1.28 KB | Suresh Prabhu Parkala |
#2 | 3192576-2.patch | 1.14 KB | blazey |
Issue fork jsonapi_menu_items-3192576
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
blazey CreditAttribution: blazey at Amazee Labs commentedDepends on #2997790: Set MenuLinkContent getEntity to public visibility
Comment #3
Deciphered CreditAttribution: Deciphered as a volunteer and at Realityloop commentedPatch needs a re-roll, and tests are currently failing, likely due to the dependency on #2997790.
Comment #4
Suresh Prabhu Parkala CreditAttribution: Suresh Prabhu Parkala at Specbee commentedRe-rolled patch. Please review.
Comment #6
Pooja Ganjage CreditAttribution: Pooja Ganjage at Asentech LLC commentedHi,
Creating a patch for solving issue that got raised in #4 comment patch.
Please review the patch.
Thanks.
Comment #7
Pooja Ganjage CreditAttribution: Pooja Ganjage at Asentech LLC commentedComment #9
Pooja Ganjage CreditAttribution: Pooja Ganjage at Asentech LLC commentedComment #10
larowlanComment #11
cola CreditAttribution: cola commentedAnyone who has a new patch for it?
Error: Call to protected method Drupal\menu_link_content\Plugin\Menu\MenuLinkContent::getEntity() from scope Drupal\jsonapi_menu_items\Resource\MenuItemsResource in Drupal\jsonapi_menu_items\Resource\MenuItemsResource->getMenuItems() (Zeile 205 in /modules/contrib/jsonapi_menu_items/src/Resource/MenuItemsResource.php)
Comment #12
Deciphered CreditAttribution: Deciphered as a volunteer and at Realityloop commentedA re-rolled patch of PR would be greatly appreciated if anyone has the capacity, otherwise I will aim to re-roll and test this in the coming weeks.
Comment #13
cola CreditAttribution: cola commentedWould be good if we can remove the dependency on Set MenuLinkContent getEntity to public visibility
Comment #14
Deciphered CreditAttribution: Deciphered as a volunteer and at Realityloop commentedComment #16
Deciphered CreditAttribution: Deciphered as a volunteer and at Realityloop commentedI've created a feature branch and merge request with the latest patch against 1.2.x. The patch can be found @ https://git.drupalcode.org/project/jsonapi_menu_items/-/merge_requests/7...
Comment #17
vermario CreditAttribution: vermario commentedHere's a revised patch against the latest version of the module
Comment #18
u_tiwari CreditAttribution: u_tiwari as a volunteer and at Axelerant commentedHere is a better version which actually seems to work correctly and is compatible with latest version.
Comment #19
jb044Rerolled against latest dev
Comment #20
andrewbelcher CreditAttribution: andrewbelcher at Access commentedThis feature actually paves way to fix a bug, which is that there are a couple broken bits of cache when using menu item content:
ResourceObject
as part of it's cache key, resulting in normalisation getting cached incorrectly for language specific requests including translated menu item content.As such, have updated the patch and updated the category/priority of this issue!
Comment #21
larowlanLooks good to me, but would be great to add tests for this because I don't want it to break again in the future, and as someone with the luxury of only working on single language sites, i18n can sometimes be an afterthought.
Comment #22
andrewbelcher CreditAttribution: andrewbelcher at Access commentedSwitched to needs work pending tests.
Have also added a new patch that fixes some indentation and an error when a menu item is not translatable.
In terms of items we need to test this with:
MenuLinkContent
Test should validate:
langcode
only included on output forMenuLinkContent
on translatable menusComment #23
Jérôme DehorterHello,
With this addition of "langcode" would it be possible to add the possibility of filtering in the API with ?filter[langcode] for example.
Comment #24
larowlanI think that's worth adding for sure, as multi-lingual sites would want that right?
Comment #25
Jérôme DehorterHello larowlan,
That's right, we have several multilingual projects and this would be to display language-specific menu items.
Comment #26
mglamanI'm assuming patch from #22 is the latest work and https://git.drupalcode.org/project/jsonapi_menu_items/-/merge_requests/7 is outdated?
Comment #27
andrewbelcher CreditAttribution: andrewbelcher commentedYes, i think so. We're running that patch in prod and it is working nicely.
Comment #28
mglaman#3276561: Add support for the Menu Item Extras module has logic for fetching the entity for menu_link_content, which is what this MR and patch are also adding. It's also using `getTranslationFromContext`. The only difference is that this adds
langcode
So I think the fix in will fix this, causing this issue to just add the langcode property.
Comment #31
mglamanI've opened https://git.drupalcode.org/project/jsonapi_menu_items/-/merge_requests/16 which is the essence of #22. The base field for the langcode field is allowed and the link's language is passed to the resource object.