function BlockForm::submitForm

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

File

core/modules/block/src/BlockForm.php, line 344

Class

BlockForm
Provides form for block instance forms.

Namespace

Drupal\block

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  parent::submitForm($form, $form_state);
  $entity = $this->entity;
  // The Block Entity form puts all block plugin form elements in the
  // settings form element, so just pass that to the block for submission.
  $sub_form_state = SubformState::createForSubform($form['settings'], $form, $form_state);
  // Call the plugin submit handler.
  $block = $entity->getPlugin();
  $this->getPluginForm($block)
    ->submitConfigurationForm($form, $sub_form_state);
  // If this block is context-aware, set the context mapping.
  if ($block instanceof ContextAwarePluginInterface && $block->getContextDefinitions()) {
    $context_mapping = $sub_form_state->getValue('context_mapping', []);
    $block->setContextMapping($context_mapping);
  }
  $this->submitVisibility($form, $form_state);
  // Save the settings of the plugin.
  $entity->save();
  $this->messenger()
    ->addStatus($this->t('The block configuration has been saved.'));
  $form_state->setRedirect('block.admin_display_theme', [
    'theme' => $form_state->getValue('theme'),
  ], [
    'query' => [
      'block-placement' => Html::getClass($this->entity
        ->id()),
    ],
  ]);
}

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