menus and hook_graphql_compose_field_results_alter

Created on 9 March 2025, about 1 month ago

Problem/Motivation

Hello, I'm wanting to modify fields returned from menus and thought hook_graphql_compose_field_results_alter would help however I don't seem to be getting the same options available as entities such as node. For example $plugin->getFieldDefinition() is always null

Also it's the menu items that I want to alter but this hook doesn't seem to trigger for those just the parent menu entity. Just wondering if there's a way this can be achieved.

💬 Support request
Status

Active

Version

2.3

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @marcus.w
  • 🇦🇺Australia almunnings Melbourne, 🇦🇺

    Mm, menus go via GraphQL in a pretty standard way, they don't go vie the GQLC field producers.

    'menu_links' loads via

        $registry->addFieldResolver('Menu', 'items',
          $builder->produce('menu_links')
            ->map('menu', $builder->fromParent())
          );
    

    Which in the GraphQL producer is:

    web/modules/contrib/graphql/src/Plugin/GraphQL/DataProducer/Menu/MenuLinks.php

    That loads up the menu tree:

        $tree = $this->menuLinkTree->load($menu->id(), new MenuTreeParameters());
    
        $manipulators = [
          ['callable' => 'menu.default_tree_manipulators:checkAccess'],
          ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
        ];
    // ... yadda yadda yadda
    

    So I don't currently have a way to altering the field results, the menu fields in the schema tap direct into props via the graphql module.

    What data were you looking to change?
    Might signal how tricky what you're trying to do is

  • 🇦🇺Australia almunnings Melbourne, 🇦🇺
Production build 0.71.5 2024