You are here

public function BlockFormBase::submitForm in Context 8.0

Same name and namespace in other branches
  1. 8.4 src/Reaction/Blocks/Form/BlockFormBase.php \Drupal\context\Reaction\Blocks\Form\BlockFormBase::submitForm()
  2. 8 src/Reaction/Blocks/Form/BlockFormBase.php \Drupal\context\Reaction\Blocks\Form\BlockFormBase::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

src/Reaction/Blocks/Form/BlockFormBase.php, line 229

Class

BlockFormBase

Namespace

Drupal\context\Reaction\Blocks\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $settings = (new FormState())
    ->setValues($form_state
    ->getValue('settings'));

  // Call the plugin submit handler.
  $this->block
    ->submitConfigurationForm($form, $settings);

  // Update the original form values.
  $form_state
    ->setValue('settings', $settings
    ->getValues());

  // Add available contexts if this is a context aware block.
  if ($this->block instanceof ContextAwarePluginInterface) {
    $this->block
      ->setContextMapping($form_state
      ->getValue([
      'settings',
      'context_mapping',
    ], []));
  }
  $configuration = array_merge($this->block
    ->getConfiguration(), [
    'region' => $form_state
      ->getValue('region'),
    'theme' => $form_state
      ->getValue('theme'),
    'unique' => $form_state
      ->getValue('unique'),
  ]);

  // Add/Update the block.
  if (!isset($configuration['uuid'])) {
    $this->reaction
      ->addBlock($configuration);
  }
  else {
    $this->reaction
      ->updateBlock($configuration['uuid'], $configuration);
  }
  $this->context
    ->save();
  $form_state
    ->setRedirectUrl(Url::fromRoute('entity.context.edit_form', [
    'context' => $this->context
      ->id(),
  ]));
}