When permissions on theme regions is enabled (with module Block Regions Permissions for example), and regions are not displayed for an user in the list for a theme, block list form submission disable all blocks for all regions for all theme.
There is no validation before the BlockListBuilder form submission. When the blocks field value is empty, all blocks are returned by loadMultiple method in submitForm, for all themes. And all blocks are disabled after submission, for all themes.
public function submitForm(array &$form, FormStateInterface $form_state) {
$entities = $this->storage->loadMultiple(array_keys($form_state->getValue('blocks')));
/** @var \Drupal\block\BlockInterface[] $entities */
foreach ($entities as $entity_id => $entity) {
$entity_values = $form_state->getValue(['blocks', $entity_id]);
$entity->setWeight($entity_values['weight']);
$entity->setRegion($entity_values['region']);
$entity->save();
}
$this->messenger->addStatus($this->t('The block settings have been updated.'));
}
To prevent this bug, I check the existence of blocks value before submission. In case of empty value for the blocks field, I prevent submission.
| Comment | File | Size | Author |
|---|---|---|---|
| block-list-form-validation.patch | 538 bytes | Arnaud.Dufresne |
Comments
Comment #2
Arnaud.Dufresne commentedComment #3
myriam_b commentedI reproduced the bug. Thanks for the patch :)
Comment #4
Arnaud.Dufresne commentedComment #5
larowlanThis feels like a feature request?
Comment #6
myriam_b commentedI don't think it is a feature request. This is a potential bug when a theme doesn't contain any blocks. LoadMultiple function load every blocks from each theme and disable them.
Comment #9
acbramley commentedThis was fixed in #2779321: Submitting empty block layout form results in breakage for all block entities