You are here

public function BlockListBuilder::submitForm in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/block/src/BlockListBuilder.php \Drupal\block\BlockListBuilder::submitForm()
  2. 9 core/modules/block/src/BlockListBuilder.php \Drupal\block\BlockListBuilder::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

core/modules/block/src/BlockListBuilder.php, line 381

Class

BlockListBuilder
Defines a class to build a listing of block entities.

Namespace

Drupal\block

Code

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.'));
}