BlockListBuilder::submitForm

public BlockListBuilder::submitForm(array &$form, FormStateInterface $form_state)

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 357

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');
}
doc_Drupal
2016-10-29 08:47:42
Comments
Leave a Comment

Please login to continue.