Problem/Motivation

As a user I want to add fields to my menu using the Menu Item Extras module.

Currently this is not possible as the Menu Items Extras module removes the menu_link_content--menu_link_content resource and replaces it with menu_link_content--MENU_ID resources.

Steps to reproduce

Install JSON:API Menu Items and Menu Link Extras and try to access a JSON:API Menu Items endpoint.

Proposed resolution

1. Stop the modules breaking when both enabled.
2. Ensure JSON:API Menu Items output field data.

Remaining tasks

1. Stop the modules breaking when both enabled.
2. Ensure JSON:API Menu Items output field data.

User interface changes

N/A

API changes

Data model changes

Command icon 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

Deciphered created an issue. See original summary.

deciphered’s picture

Status: Active » Needs work
StatusFileSize
new1.83 KB

This is related to #3217476, but I'm not sure that that issue was caused by Menu Item Extras.

I have created a patch that resolves the Null resource type error when Menu Item Extras is installed, but it might be better to look at a generic solution as well, removing the dependency on the menu_link_content resource type and providing an alternative fallback resource type.

The patch doesn't yet expose the Menu Item Extras fields, so more work is required either way.

cweagans’s picture

Status: Needs work » Needs review
StatusFileSize
new11.32 KB

Updated the patch above to add support for displaying field values (+ use DI for various services).

Status: Needs review » Needs work

The last submitted patch, 3: 3276561-03-menu_item_extras_support.patch, failed testing. View results

cweagans’s picture

StatusFileSize
new11.27 KB
cweagans’s picture

Status: Needs work » Needs review
agiraud’s picture

Thanks for the patch in #5 @cweagans !

I was implementing custom icon fields for my Drupal menu (with menu item extras) and I wanted to display it on my nextjs frontend, your patch is working great (Drupal core 9.4).

eglaw’s picture

With addition of the menu_item_extras module (the one that adds the possibility to extend simple menu_link_contents with Field UI, and basically transforming it in a fully usable content entity, it also introduces it to the View Modes. The previous patch (although completely functioning and awesome, it lacks the including the info of the view_mode.

I've modified it a little to include the missing info.

switcode’s picture

I've added event dispatcher AdditionalFieldsEvent to add extra fields the response
I've added EventSubscriber MenuItemExtraSubscriber to add extra Menu items fields to the response

rakesh.gectcr’s picture

#9 works fine with Drupal 10!

bojan_dev’s picture

Rerolled #7 + added some coding standards fixes

Arlina made their first commit to this issue’s fork.

arlina’s picture

In #13: created a PR from patch #11, and it also adds caching to the getRouteResourceTypes() method, as that was causing memory issues on sites with a large number of menus.

rdoepner’s picture

Add language support.

mglaman’s picture

Assigned: Unassigned » mglaman

I'll pick this up to review and get merged!

mglaman’s picture

Hiding some patches. Need to see what #15 provides that isn't in the MR. No interdiff, but language support is a good thing. Or it should be done in #3192576: Add langcode & fix content caching

mglaman’s picture

Wrote a test and it looks like this MR broke when a menu has plugin-based menu links, working on a fix. See https://git.drupalcode.org/project/jsonapi_menu_items/-/merge_requests/1...

mglaman’s picture

The MR addresses #15 by leveraging `\Drupal\menu_link_content\Plugin\Menu\MenuLinkContent::getEntity` which loads the entity from context for the proper translation of entity fields.

mglaman’s picture

Assigned: mglaman » Unassigned

Okay, I think this is all set for review now! Thanks everyone for the work. I made it a bit more generic so that if anyone made menu_link_content fieldable without menu_item_extras it also works.

mglaman’s picture

Marking issue credit

mglaman’s picture

Status: Needs review » Reviewed & tested by the community

This passed several rounds on internal QA on our side, I'm going to merge so we can unblock #3192576: Add langcode & fix content caching

  • mglaman committed 9cac8fa2 on 1.2.x authored by Arlina
    Issue #3276561 by mglaman, cweagans, Arlina, Deciphered, eglaw, switcode...
mglaman’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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