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.

CommentFileSizeAuthor
block-list-form-validation.patch538 bytesArnaud.Dufresne

Comments

Arnaud.Dufresne created an issue. See original summary.

Arnaud.Dufresne’s picture

Issue summary: View changes
myriam_b’s picture

I reproduced the bug. Thanks for the patch :)

Arnaud.Dufresne’s picture

Issue summary: View changes
larowlan’s picture

Issue tags: +Blocks-Layouts

This feels like a feature request?

myriam_b’s picture

I 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.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

acbramley’s picture

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.