Verified Commit 60ce4e14 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2779321 by nedjo, Akram Khan, smustgrave, catch, Meenakshi_j, pooja...

Issue #2779321 by nedjo, Akram Khan, smustgrave, catch, Meenakshi_j, pooja saraah, Berdir, alexpott: Submitting empty block layout form results in breakage for all block entities

(cherry picked from commit b5b29516)
parent ba61f32a
Loading
Loading
Loading
Loading
+8 −11
Original line number Diff line number Diff line
@@ -373,7 +373,7 @@ public function getDefaultOperations(EntityInterface $entity) {
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    if (empty($form_state->getValue('blocks'))) {
      $form_state->setErrorByName('blocks', 'No blocks settings to update.');
      $form_state->setErrorByName('blocks', $this->t('No blocks settings to update.'));
    }

  }
@@ -383,8 +383,6 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $blocks = $form_state->getValue('blocks');
    // Passing empty value to load Multiple would load all items from storage.
    if (!empty($blocks)) {
    $entities = $this->storage->loadMultiple(array_keys($blocks));
    /** @var \Drupal\block\BlockInterface[] $entities */
    foreach ($entities as $entity_id => $entity) {
@@ -393,7 +391,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
      $entity->setRegion($entity_values['region']);
      $entity->save();
    }
    }
    $this->messenger->addStatus($this->t('The block settings have been updated.'));
  }

+3 −1
Original line number Diff line number Diff line
@@ -108,7 +108,8 @@ public function testBlockDemoUiPage() {
    $this->drupalGet('admin/structure/block/demo/stable9');
    $this->assertSession()->statusCodeEquals(404);

    // Delete all blocks and verify block layout can be saved.
    // Delete all blocks and verify saving the block layout results in a
    // validation error.
    $block_storage = \Drupal::service('entity_type.manager')->getStorage('block');
    $blocks = $block_storage->loadMultiple();
    foreach ($blocks as $block) {
@@ -118,6 +119,7 @@ public function testBlockDemoUiPage() {
    $blocks_table = $this->xpath("//tr[@class='block-enabled']");
    $this->assertEmpty($blocks_table, 'The blocks table is now empty.');
    $this->submitForm([], 'Save blocks');
    $this->assertSession()->pageTextContains('No blocks settings to update');

  }