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
- Upgrade Context to any version from 8.x-4.0-beta3 or later.
- Place menu blocks on the site using a context.
- 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.
Comment | File | Size | Author |
---|---|---|---|
verify_that_block_is_an_object_with_getresult.patch | 1021 bytes | wsantell |
Issue fork uswds-3174443
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
Comment #2
wsantell CreditAttribution: wsantell commentedComment #3
Irisibk CreditAttribution: Irisibk at CivicActions for National Science Foundation commentedComment #4
majorrobot CreditAttribution: majorrobot at CivicActions for Global Game Jam commentedWe ran into the same issue as OP, with the exception that:
+1 for the patch. We tried it out, and it worked well.
Comment #6
jrglasgow CreditAttribution: jrglasgow commentedTook a look at this patch and it appears to be logical, but for me there are too many nested if statements.
Comment #9
jrglasgow CreditAttribution: jrglasgow commentedComment #10
emanaton CreditAttribution: emanaton commentedNOTE: 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