Problem/Motivation

We use Context to place menu blocks on our website. Context 8.x-4.0-beta5 was just released and when we upgraded the site would throw an error containing this information:
Error: Call to a member function getRegion() on null in ...uswds/includes/menus.inc on line 39

Steps to reproduce

  1. Upgrade Context to any version from 8.x-4.0-beta3 or later.
  2. Place menu blocks on the site using a context.
  3. Go to a page where the context is active.

Proposed resolution

This is caused because Context adds custom IDs to the menu blocks. In example, for the main menu ID it takes the plugin ID "menu_block:main" and creates a custom ID called "menu_block_main". The uswds_theme_suggestions_block_alter() function detects this custom ID and calls Block::load() on it, then assumes a block was loaded.
The attached patch makes sure that $block is an object and has the getResult property before attempting to get that property.

Note
This may be an improper way to add the ID on Context's part, but when checking this against their 8.x-4.0-beta2 branch, uswds_theme_suggestions_block_alter() does not find any IDs for the blocks, so theme suggestions aren't being added in either case.

Issue fork uswds-3174443

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wsantell created an issue. See original summary.

wsantell’s picture

Issue summary: View changes
Irisibk’s picture

Status: Active » Needs review
majorrobot’s picture

We ran into the same issue as OP, with the exception that:

  1. Everything worked fine until I moved our custom blocks from one region to another.
  2. We're using Composer 8.x-4.0-beta6.

+1 for the patch. We tried it out, and it worked well.

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

jrglasgow’s picture

Took a look at this patch and it appears to be logical, but for me there are too many nested if statements.

  • jrglasgow committed 9d56c83 on 8.x-2.x
    Issue #3174443: Site errors if used with Context 8.x-4.0-beta3+ to place...
jrglasgow’s picture

Status: Needs review » Fixed
emanaton’s picture

NOTE: There was a small but significant typo in this fix. A patch for this against the 2.1 branch can be found here: https://www.drupal.org/project/uswds/issues/3224041

Status: Fixed » Closed (fixed)

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