Problem/Motivation

After checking the box to "Show Global blocks" on a block visibility group, all blocks, across all themes, vanish and menu tabs no longer appear on administration pages.

Below the exact steps to reproduce the bug.

From a fresh D8 install on simplytest.me (standard profile):

- Enable Block visibility group
- From Structure > Block layout, click on the the link create a group
- Create a group "test" with the default settings "All conditions must pass" enabled
- Return to the Block layout page
- In the select list "Block visibility group" select the group created "test"
- Uncheck the checkbox " Show Global blocks"
- And now check the same checkbox "Show Global blocks"

And all the block instance are gone.

Additional information:

  • The follow error appears in the log:

    Warning: array_keys() expects parameter 1 to be array, string given in Drupal\block\BlockListBuilder->submitForm() (line 358 of /home/rr4dx/www/core/modules/block/src/BlockListBuilder.php).

  • Block configuration items still exist, but have missing data. Example:
    uuid: b62f7d61-4a22-499a-b293-5157a32010ae
    langcode: en
    status: true
    dependencies:
      module:
        - system
      theme:
        - bartik
    _core:
      default_config_hash: 9EoWV2Lot6FVSr50t4hoKgiz1LIXYWNG-IIPYsWxBqo
    id: bartik_content
    theme: bartik
    region: null
    weight: null
    provider: null
    plugin: system_main_block
    settings:
      id: system_main_block
      label: 'Main page content'
      provider: system
      label_display: '0'
    visibility: {  }
    

    Values for region and weight are not expected to be null.

Source of bug:

  • In BlockVisibilityGroupedListBuilder::submitForm() we call the parent ::submitForm() method.
  • BlockListBuilder::submitform() examines a $form_state value to determine the blocks being edited and then loads them. In our case, the value passed to the storage's ::loadMultiple() method is NULL and so all configuration entities in the storage (not only blocks) are loaded, iterated, modified, and saved.
  • For most configuration entities, this processing may make no difference, but depending on the entity type it can lead to a broken state. Specifically, since the weight property is reset to NULL, this may break menu configuration entities.

Proposed resolution

In BlockVisibilityGroupedListBuilder::submitForm(), examine the 'blocks' value in the $form_state. If empty, skip calling the parent ::submitForm() method to avoid triggering the bug.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eswiderski created an issue. See original summary.

carsonblack’s picture

I found the same issue. Which wiped out the block that allow you to get to the Seven admin theme blocks layout which is slightly painful. If you need to get there go to admin/structure/block/list/seven

flocondetoile’s picture

Title: Killed All Blocks » All Blocks removed from regions after creating a block visibility group
Priority: Normal » Critical

Same issue. After creating some block visibility groups, going to the block page layout, all blocks have been removed, on all themes. All your stuff is gone :-( The issue is still here after uninstall the module. Bumping this to critical as you lost all yours block's configurations.

edit : on Drupal 8.0.6

snsblvd’s picture

Same issue here, too. With Drupal 8.1.2. The whole block stuff is gone amok and even some admin views are damaged (no tabs e.g. in the configuration management).

CuriousTo’s picture

FileSize
37.04 KB

Same issue here, but the error occurs when i unclick the "show Global Blocks" in the structure block list after creating a visibility group.

I've tried with drupal 8.1.1 and 8.1.3.

gillesv’s picture

We're experiencing the same issue. The deletion was also triggered by unchecking "show Global Blocks" after creating a new group, as described by CuriousTo

tngvndrm’s picture

same here.

nedjo’s picture

Clearly there's a bug, but we don't yet have clear steps to reproduce it. I, for instance, have been using the module and successfully created visibility groups and assigned blocks to them without hitting this issue.

I've added the "Needs steps to reproduce" tag. Please see the documentation on how to document steps to reproduce a reported issue. Doing so will make it a lot easier for someone to troubleshoot. Thanks!

Joao Informatico madrid’s picture

Same here.

TO reproduce try to install module after create some blocks,
Create a group at /admin/structure/block/block-visibility-group
Create rule from group
Go to admin block again at /admin/structure/block
Select you group block.
Try to Change some group settings here, at /admin/structure/block.

In other hand.
I did try create blocks again after all blocks was removed. And the machine name of blocks still are in database

nickBumgarner’s picture

I've also noticed this issue. If you go into a block visibility group and start adding blocks back in they will show up, but the machine names are all changed. It's creating another instance of the blocks. I noticed this because after placing the blocks my theme selectors were broken. I really need something like this to work. Otherwise, module seems pretty cool.

nedjo’s picture

I've tried unsuccessfully to reproduce this issue. If you can reproduce this from a fresh install, please list the exact steps. (@Joao Informatico madrid: thanks for listing steps, but I was unable to reproduce the issue following them.)

Here are the steps I took:

  • Start with a fresh install of Drupal core, using the "Standard" install profile.
  • Under Structure > Block layout > Custom block library, create a custom block and place it in the "Content" region.
  • Install Block Visibility Groups.
  • At Structure > Block layout, click the link "Create a Group" and add a new group, leaving the group settings at the default.
  • At Structure > Block layout, note that all blocks are listed as expected, including the custom block you created. Use the "Block Visibility Groups" select to select the one you just created.
  • The page reloads and you get all blocks shown with a visibility group of "Global", including the custom block you created.
  • Edit one of the blocks by clicking its "configure" link. The block visibility group you're in is automatically selected. Click "Save block". Your block now shows as being in the active block visibility group.

Following these steps, everything works as expected.

If you are able to reliably reproduce this issue, please list the exact steps, starting with a fresh install. simplytest.me is a quick way to install a new site--just put block_visibility_groups in the "Enter project name" field.

flocondetoile’s picture

Below the exact steps to reproduce the bug

On a fresh D8 install on simplytest.me (standard profile)

- Enable Block visibility group
- From Structure > Block layout, click on the the link create a group
- Create a group "test" with the default settings "All conditions must pass" enabled
- Return to the Block layout page
- In the select list "Block visibility group" select the group created "test"
- Uncheck the checkbox " Show Global blocks"
- And now check the same checkbox "Show Global blocks"

And all the block instances are gone, on every themes.

I'm able to reliably reproduce this issue. 3 times on 3 different instances launched on simplytest.me with these exact steps.

flocondetoile’s picture

Issue summary: View changes

updating issue summary

nedjo’s picture

Title: All Blocks removed from regions after creating a block visibility group » All Blocks removed from regions after checking "Show Global blocks"
Issue summary: View changes
Issue tags: -Needs steps to reproduce

@flocondetoile: thanks, that helps a lot! Confirmed that the steps reproduce the issue.

Additional information:

  • The follow error appears in the log:

    Warning: array_keys() expects parameter 1 to be array, string given in Drupal\block\BlockListBuilder->submitForm() (line 358 of /home/rr4dx/www/core/modules/block/src/BlockListBuilder.php).

  • Block configuration items still exist, but have missing data. Example:
    uuid: b62f7d61-4a22-499a-b293-5157a32010ae
    langcode: en
    status: true
    dependencies:
      module:
        - system
      theme:
        - bartik
    _core:
      default_config_hash: 9EoWV2Lot6FVSr50t4hoKgiz1LIXYWNG-IIPYsWxBqo
    id: bartik_content
    theme: bartik
    region: null
    weight: null
    provider: null
    plugin: system_main_block
    settings:
      id: system_main_block
      label: 'Main page content'
      provider: system
      label_display: '0'
    visibility: {  }
    

    Values for region and weight are not expected to be null.

nedjo’s picture

Version: 8.x-1.0 » 8.x-1.x-dev
Component: User interface » Code
Assigned: Unassigned » nedjo

What appears to be happening is:

  • In BlockVisibilityGroupedListBuilder::submitForm() we call the parent ::submitForm() method.
  • BlockListBuilder::submitform() examines a $form_state value to determine the blocks being edited and then loads them. In our case, the value passed to the storage's ::loadMultiple() method is NULL and so all configuration entities in the storage (not only blocks) are loaded, iterated, modified, and saved.
  • For most configuration entities, this processing may make no difference, but depending on the entity type it can lead to a broken state. Specifically, since the weight property is reset to NULL, this may break menu configuration entities.

Working on a patch.

nedjo’s picture

This issue is a core bug rather than one that's strictly caused by Block Visibility Groups, since any time you submit a blocks admin form that lacks any blocks this bug will be triggered. In practice, this isn't likely to happen in core, since core provides multiple blocks that are by default available to all themes.

Before punting to the core issue queue, though, here's a patch that skips calling the parent ::submitForm() method if 'blocks' value is empty.

If you already have a site broken by this bug, this patch unfortunately won't help you fix it.

Status: Needs review » Needs work

The last submitted patch, 16: block_visibility_groups-global-2677574-16.patch, failed testing.

The last submitted patch, 16: block_visibility_groups-global-2677574-16.patch, failed testing.

nickBumgarner’s picture

Patch 16 Worked great for me. Thanks nedjo, you just saved me a lot of trouble!

steveoliver’s picture

I noticed the fail in the last test result in this issue comes from #2608736. I updated that issue and related it to this issue. If anyone wants to resolve that issue first, maybe this will become visibly ready to commit.

nedjo’s picture

Assigned: nedjo » Unassigned
Status: Needs work » Needs review

  • tedbow committed c0851e9 on 8.x-1.x authored by nedjo
    Issue #2677574 by nedjo: All Blocks removed from regions after checking...
tedbow’s picture

Status: Needs review » Fixed

@nedjo nice catch and thanks for the patch! Thanks everyone for reporting this and information!

Status: Fixed » Closed (fixed)

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