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
andweight
are not expected to benull
.
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 isNULL
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.
Comments
Comment #2
carsonblack CreditAttribution: carsonblack commentedI 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
Comment #3
flocondetoileSame 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
Comment #4
snsblvd CreditAttribution: snsblvd as a volunteer commentedSame 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).
Comment #5
CuriousTo CreditAttribution: CuriousTo commentedSame 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.
Comment #6
gillesv CreditAttribution: gillesv commentedWe're experiencing the same issue. The deletion was also triggered by unchecking "show Global Blocks" after creating a new group, as described by CuriousTo
Comment #7
tngvndrm CreditAttribution: tngvndrm commentedsame here.
Comment #8
nedjoClearly 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!
Comment #9
Joao Informatico madrid CreditAttribution: Joao Informatico madrid commentedSame 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
Comment #10
nickBumgarner CreditAttribution: nickBumgarner at Inclind Inc commentedI'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.
Comment #11
nedjoI'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:
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.
Comment #12
flocondetoileBelow 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.
Comment #13
flocondetoileupdating issue summary
Comment #14
nedjo@flocondetoile: thanks, that helps a lot! Confirmed that the steps reproduce the issue.
Additional information:
Values for
region
andweight
are not expected to benull
.Comment #15
nedjoWhat appears to be happening is:
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 isNULL
and so all configuration entities in the storage (not only blocks) are loaded, iterated, modified, and saved.NULL
, this may break menu configuration entities.Working on a patch.
Comment #16
nedjoThis 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.
Comment #19
nickBumgarner CreditAttribution: nickBumgarner at Inclind Inc commentedPatch 16 Worked great for me. Thanks nedjo, you just saved me a lot of trouble!
Comment #20
steveoliver CreditAttribution: steveoliver commentedI 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.
Comment #21
nedjoI opened a core bug report, #2779321: Submitting empty block layout form results in breakage for all block entities.
Comment #23
tedbow@nedjo nice catch and thanks for the patch! Thanks everyone for reporting this and information!