We need a way for supporting Menu Item Extras in menu items

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

mcortes19 created an issue. See original summary.

cedricl’s picture

StatusFileSize
new6.74 KB

We did this, but made it hardcoded only for the fields we needed, you can take a look in our module for inspiration.

mcortes19’s picture

Thanks @CedricL, I'll definitely use it as inspiration and hopefully as a basis for contributing.

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

almunnings’s picture

Howdy, MR is in, please test and let me know.
Because we don't "out of the box" support a union of MenuItem types, I've added it to an `extras` field.

Then I messed about with some of the form UX to make it less.. crap to work with.

Enable the MenuLinkContent entity fields on Menu in the GraphQL Compose schema form.

Screenshot

Query on the MenuItem.extras union.

Screenshot

{
  menu(name: MAIN) {
    items {
      extras {
        ... on MenuLinkContentMain {
          kitties
        }
      }
    }
  }
}

Also added on MenuItem.langcodeLanguage

almunnings’s picture

Status: Active » Needs review
mcortes19’s picture

@almunnings I tested on the D10.8 site and it returned the following error: For error #0: Error: Call to protected method Drupal\menu_link_content\Plugin\Menu\MenuLinkContent::getEntity() from scope Drupal\graphql_compose_menus\Plugin\GraphQL\DataProducer\MenuTreeLinkEntity in Drupal\graphql_compose_menus\Plugin\GraphQL\DataProducer\MenuTreeLinkEntity->resolve() (line 45 of /app/web/modules/contrib/graphql_compose/modules/graphql_compose_menus/src/Plugin/GraphQL/DataProducer/MenuTreeLinkEntity.php)

Seems like the `getEntity()` method is public until D10.2 and many sites are not ready to move to D10.2

almunnings’s picture

Status: Needs review » Needs work
almunnings’s picture

Status: Needs work » Needs review

Ok,
So thats updated now to use a buffer again.

Wondering if the semantics are now correct.
is extras ok?
should it be fields

Or do we completely mess with the menu system and clean it up to make more sense if this is an actual entity now.

Keen for feedback, as i dont feel like going...

menu(name: MAIN) {
  items {
    extras {
      ... on MyThingyMenuWhatever {
        thing
      }
    }
  }
}

Does it really mean anything to anyone? It feels like a total after thought. Theres gotta be an "if i didn't have to support any legacy stuff, this is the ideal structure" moment, somewhere?

Its a strange one, because without the module, the menu item isn't really an entity, its got no unique properties by type.

Maybe hijacking the attributes field is a better usage.

Have a play
Keen on feedback
Worm regards

almunnings’s picture

Status: Needs review » Needs work

Will write up some tests tonight and get this in.

almunnings’s picture

Status: Needs work » Fixed

almunnings’s picture

Status: Fixed » Closed (fixed)

Beta 2 tagged, thanks all