Group Menu Block doesn't show in Drupal 9 - The node context is not a valid context

Created on 29 March 2021, about 3 years ago
Updated 5 July 2023, 12 months ago

Problem/Motivation

On a Drupal 9 instance

After enabling groupmenu_block submodule and creating an instance of the Group Menu block visits to any page where the block was rendered resulted in an error message in my logs.

NOTICE: PHP message: Uncaught PHP Exception Drupal\Component\Plugin\Exception\ContextException: "The node context is not a valid context." at /var/www/html/web/core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php line 188

After removing the block the error went away. This led me to find a change report that changes the key on the annotation for context definitions that the block needs.

https://www.drupal.org/node/3016699 β†’

After updating the key from context to context_definitions the problem went away but I still did not observe the group menus as expected.

After editing the block configuration I noted that the form now had extra form inputs for setting the group and node contexts that were not available before the patch had been applied.

Steps to reproduce

Using Group 8.x-1.3 with patch from #239 for the entity strings issue
Enable Group Menu module (8.x-1.0-beta2)
Attach a group menu plugin to a group type.
Create a group menu from the group -> menus -> add group menu
Place Group Menu block in a region on the Structure -> Block Layout page
*observe the missing node and group context options without the patch*
Visit the homepage or a page with the rendered region / block and you should get the above mentioned PHP error and a whitescreen / PHP error message depending on your configuration.

Proposed resolution

Fix the context definition key per the change record.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States dasginganinja Bethlehem, PA

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States rs3876

    I have Drupal 9.5.9, Group 8.x-1.5 and Groupmenu 8.x-1.0-beta3
    Groupmenu is not showing. I tried the following lines without any luck.
    --------------- code -------------------
    $block_manager = \Drupal::service('plugin.manager.block');
    $plugin_block = $block_manager->createInstance('groupmenus');
    $plugin_block->setContextValue('group', $group);
    $block = $plugin_block->build();
    -------------------------------------------
    Error I get when using setContextValue() in above code.
    ---------------- Error----------------------
    Uncaught PHP Exception Drupal\Component\Plugin\Exception\ContextException: "The group context is not a valid context." at \web\core\lib\Drupal\Core\Plugin\ContextAwarePluginTrait.php line 184
    ---------------------------------------------

    I also tried 2 patches following patches mentioned in above comment #7. I had to make changes to make patch 1 compatible with D-9.
    ---------------------- Patches-------------------
    patch 1 - https://www.drupal.org/files/issues/2018-08-28/group-configurable-entiti... β†’
    patch 2- https://www.drupal.org/files/issues/2019-04-04/groupmenu-change_referenc... β†’
    ---------------------------------------------------

    Not sure if I am on right path. Looking for help.

  • πŸ‡ΊπŸ‡ΈUnited States ao5357

    As a note, I applied similar changes to these patches in the issue fork for https://www.drupal.org/project/groupmenu/issues/3351701 πŸ› Group menu compatibility with group V2 and V3 Needs review and was able to get the menu tree to appear in that fork per #7 .

    The trick, at least in the issue fork, was to switch $menu_name to $menu->id() in the build() method's foreach loop, where it loads the menuTree(s). See https://git.drupalcode.org/issue/groupmenu-3351701/-/blob/3351701-group-...

Production build 0.69.0 2024