function BlockListBuilder::submitForm

Same name in other branches
  1. 8.9.x core/modules/block/src/BlockListBuilder.php \Drupal\block\BlockListBuilder::submitForm()
  2. 10 core/modules/block/src/BlockListBuilder.php \Drupal\block\BlockListBuilder::submitForm()
  3. 11.x core/modules/block/src/BlockListBuilder.php \Drupal\block\BlockListBuilder::submitForm()

Overrides FormInterface::submitForm

File

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

Class

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

Namespace

Drupal\block

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
    $blocks = $form_state->getValue('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,
        ]);
        $entity->setWeight($entity_values['weight']);
        $entity->setRegion($entity_values['region']);
        $entity->save();
    }
    $this->messenger
        ->addStatus($this->t('The block settings have been updated.'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.