I am getting the following on a fresh install of menu_block:

Notice: Undefined index: region in Drupal\menu_block\Plugin\Block\MenuBlock->build() (line 152 of modules/contrib/menu_block/src/Plugin/Block/MenuBlock.php).
Notice: Undefined index: uuid in Drupal\menu_block\Plugin\Block\MenuBlock->build() (line 153 of modules/contrib/menu_block/src/Plugin/Block/MenuBlock.php).
Notice: Undefined index: region in menu_block_theme_suggestions_block() (line 15 of modules/contrib/menu_block/menu_block.module).
Notice: Undefined index: uuid in menu_block_theme_suggestions_block() (line 16 of modules/contrib/menu_block/menu_block.module).

Is anyone else getting the same issue? Seems like the 'region' and 'uuid' array key is not available in the $variables['elements']['#configuration'] array?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ellioseven created an issue. See original summary.

ellioseven’s picture

Issue summary: View changes
ellioseven’s picture

Issue summary: View changes
ellioseven’s picture

Issue summary: View changes
ellioseven’s picture

Issue summary: View changes
Ramdas Gaikar’s picture

Hi ellioseven,

I am not able to reproduce this issue.

I am using Seven as admin and Bartik as default theme.

chrisfromredfin’s picture

I am also just seeing this issue. I just installed 8.x-1.1 on an existing site.

chrisfromredfin’s picture

FileSize
10.1 KB
ellioseven’s picture

I am submitting a patch that checks if the block has a correlating configuration entity. If so, it will load it up and pass the region and UUID to default configuration. Seems to be working for me, however doesn't look like any tests are available with the 8.x-1.1 branch.

4aficiona2’s picture

I can confirm this. Just installed menu_block 8.x-1.1 on an existing site and I also get this notice / error.

chrisfromredfin’s picture

This patch seems to be working for me. I've re-rolled the patch from the module root instead of the Drupal root.

aleksip’s picture

Status: Active » Needs review
jhuhta’s picture

The patch seems to be working fine for me too.

jlockhart’s picture

This solved the issue for us as well.

JeroenT’s picture

Status: Needs review » Reviewed & tested by the community

Patch also fixed the problem for me.

JohnAlbin’s picture

Status: Reviewed & tested by the community » Needs work

I can't reproduce this error. The region and uuid configuration are provided to all blocks in regions. Are you using a module to render a block outside of a normal page region?

Also, I'm testing on the latest Drupal 8.1.x core version with the standard installation profile. Which core version are you all using?

I am submitting a patch that checks if the block has a correlating configuration entity.

The configuration of the element is already provided in $variables['elements']['#configuration'], so the code feels redundant to me. Also, the patch doesn't grab _this_ block's config. It grabs the first menu_block config in the system; if you have more than 1 config, only 1 block will get the correct config.

4alldigital’s picture

I have this too. Looks like 'region' and 'uuid' are definitely missing from $this->configuration in MenuBlock.php. Have repeated/tested on 2 separate Drupal installs.

line 150:

$build['#theme'] = 'menu__menu_block_'
      . strtr($menu_name, '-', '_')
      . '_region_' . $this->configuration['region']
      . '_uid_' . strtr($this->configuration['uuid'], '-', '_');
    return $build;
4alldigital’s picture

Attached screen grab of KINT debug of $this->configuration immediately prior to use (see previous comment) . If this helps at all.

morenstrat’s picture

Patch from #11 does not fix the issue if you have two menu blocks in different regions because it always uses the first config entity.

dawehner’s picture

The region should not be available as part of the configuration of a block. Block plugins are designed to be rendered outside of the block UI, so for example in panels.
In there you don't have a block entity for every block, but rather one big page_manager configuration for all the blocks.

osman’s picture

There is a change record regarding region name being removed from `suggestions`:

Per-region block markup and per-region block templating feature removed
https://www.drupal.org/node/2011434

So, how does menu_block_theme_suggestions_block() incorporates region specific suggestions?
(Not sure about uuid based suggestions though.)

Also, when I try to output variables, none of the blocks I have (core, custom and menu blocks), populated region or uuid keys:

function menu_block_theme_suggestions_block(array $variables) {
  $suggestions = array();

  kint_require();
  Kint::dump($variables);

  ...

}
osman’s picture

davebeach’s picture

I got this problem a few times; after I deleted structures related to menu_block. The only way I could correct the problem is to completely uninstall it. Then reinstall.

Also to avoid having this error out in production. In your settings.yml file (sites>default>settings.yml).
Uncomment:
$conf['error_level'] = 0;

To uninstall via drush:

  1. 1. Put site in maintenance mode: drush sset system.maintenance_mode 1
  2. 2. Remove anything tied to menu_block in structures.
  3. 3. Uninstall module: drush pm-uninstall menu_block
  4. 4. Reinstall menu_block: drush dl menu_block
  5. 5. Activate menu_block: drush en menu_block
JohnAlbin’s picture

Assigned: Unassigned » JohnAlbin

@osman Thank you for pointing to the change record! It looks like System menu block's were supposed to be able to get context (like region placement) with a follow-up patch, but they never did. :-(

The region and uuid configuration are provided to all blocks in regions. Are you using a module to render a block outside of a normal page region?

Ugh. It was me who was using an extra module. Context module is stuffing those extra things into the config. I'll have to rip those theme hook suggestions out. :-p

generalredneck’s picture

Pretty sure you can recreate this using a panels page and rendering the block inside one of the regions in the layout.

becw’s picture

Title: Undefined Index » Undefined Index in menu_block_theme_suggestions_block() and MenuBlock->build()
Version: 8.x-1.1 » 8.x-1.2
Status: Needs work » Needs review

I ran into this issue too. It sounds like the issue is that menu_block expects some contextual information for blocks that core does not provide, and that the patch in #11 adds that information. In my testing, this patch resolves the PHP notices.

I think that #11 just needs a review?

jamievereecken’s picture

Patch in #11 fixed the problem for me.

DamienMcKenna’s picture

Version: 8.x-1.2 » 8.x-1.x-dev
chrisfromredfin’s picture

Status: Needs review » Needs work

I believe the consensus is the patch in #11 doesn't work for multiple menu blocks, as it hardcodes the delta [0].

DamienMcKenna’s picture

FYI the patch in #11 appears to work as a bandaid for limited use cases, though clearly it needs some work. Sites that are experiencing this problem may wish to test out the patch, but it isn't guaranteed to fix the problem and may cause others.

JohnAlbin’s picture

I've got the fix for this. Will commit shortly.

  • JohnAlbin committed 507bfe7 on 8.x-1.x
    Issue #2759019 by cwells, ellioseven, osman, 4alldigital, JohnAlbin,...
JohnAlbin’s picture

Assigned: JohnAlbin » Unassigned
Status: Needs work » Fixed
ChandeepKhosa’s picture

thanks a lot John, looking forward to removing the patch for this I had in my repo :)

Status: Fixed » Closed (fixed)

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