You are here

public function BlockListBuilder::submitForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 362
Contains \Drupal\block\BlockListBuilder.

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(array(
      'blocks',
      $entity_id,
    ));
    $entity
      ->setWeight($entity_values['weight']);
    $entity
      ->setRegion($entity_values['region']);
    if ($entity
      ->getRegion() == BlockInterface::BLOCK_REGION_NONE) {
      $entity
        ->disable();
    }
    else {
      $entity
        ->enable();
    }
    $entity
      ->save();
  }
  drupal_set_message(t('The block settings have been updated.'));

  // Remove any previously set block placement.
  $this->request->query
    ->remove('block-placement');
}