Loading core/modules/block/src/BlockListBuilder.php +15 −8 Original line number Diff line number Diff line Loading @@ -372,14 +372,20 @@ public function getDefaultOperations(EntityInterface $entity) { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { // No validation. if (empty($form_state->getValue('blocks'))) { $form_state->setErrorByName('blocks', 'No blocks settings to update.'); } } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $entities = $this->storage->loadMultiple(array_keys($form_state->getValue('blocks'))); $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) { $entity_values = $form_state->getValue(['blocks', $entity_id]); Loading @@ -387,6 +393,7 @@ 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.')); } Loading core/modules/block/tests/src/Functional/BlockUiTest.php +12 −0 Original line number Diff line number Diff line Loading @@ -107,6 +107,18 @@ public function testBlockDemoUiPage() { \Drupal::service('theme_installer')->install(['stable9']); $this->drupalGet('admin/structure/block/demo/stable9'); $this->assertSession()->statusCodeEquals(404); // Delete all blocks and verify block layout can be saved. $block_storage = \Drupal::service('entity_type.manager')->getStorage('block'); $blocks = $block_storage->loadMultiple(); foreach ($blocks as $block) { $block->delete(); } $this->drupalGet('admin/structure/block'); $blocks_table = $this->xpath("//tr[@class='block-enabled']"); $this->assertEmpty($blocks_table, 'The blocks table is now empty.'); $this->submitForm([], 'Save blocks'); } /** Loading Loading
core/modules/block/src/BlockListBuilder.php +15 −8 Original line number Diff line number Diff line Loading @@ -372,14 +372,20 @@ public function getDefaultOperations(EntityInterface $entity) { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { // No validation. if (empty($form_state->getValue('blocks'))) { $form_state->setErrorByName('blocks', 'No blocks settings to update.'); } } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $entities = $this->storage->loadMultiple(array_keys($form_state->getValue('blocks'))); $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) { $entity_values = $form_state->getValue(['blocks', $entity_id]); Loading @@ -387,6 +393,7 @@ 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.')); } Loading
core/modules/block/tests/src/Functional/BlockUiTest.php +12 −0 Original line number Diff line number Diff line Loading @@ -107,6 +107,18 @@ public function testBlockDemoUiPage() { \Drupal::service('theme_installer')->install(['stable9']); $this->drupalGet('admin/structure/block/demo/stable9'); $this->assertSession()->statusCodeEquals(404); // Delete all blocks and verify block layout can be saved. $block_storage = \Drupal::service('entity_type.manager')->getStorage('block'); $blocks = $block_storage->loadMultiple(); foreach ($blocks as $block) { $block->delete(); } $this->drupalGet('admin/structure/block'); $blocks_table = $this->xpath("//tr[@class='block-enabled']"); $this->assertEmpty($blocks_table, 'The blocks table is now empty.'); $this->submitForm([], 'Save blocks'); } /** Loading