You are here

public function BlockFieldConfigForm::submitForm in Display Suite 8.3

Same name and namespace in other branches
  1. 8.4 src/Form/BlockFieldConfigForm.php \Drupal\ds\Form\BlockFieldConfigForm::submitForm()
  2. 8.2 src/Form/BlockFieldConfigForm.php \Drupal\ds\Form\BlockFieldConfigForm::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 FieldFormBase::submitForm

File

src/Form/BlockFieldConfigForm.php, line 119

Class

BlockFieldConfigForm
Configure block fields.

Namespace

Drupal\ds\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $field = $this->field;

  // Create an instance of the block.

  /* @var $block BlockPluginInterface */
  $manager = \Drupal::service('plugin.manager.block');
  $block_id = $field['properties']['block'];
  $block = $manager
    ->createInstance($block_id);

  // Process block config data using the block's submit handler.
  $block
    ->blockSubmit($form, $form_state);

  // If the block is context aware, store the context mapping.
  if ($block instanceof ContextAwarePluginInterface && $block
    ->getContextDefinitions()) {
    $context_mapping = $form_state
      ->getValue('context_mapping', []);
    $block
      ->setContextMapping($context_mapping);
  }
  $block_config = $block
    ->getConfiguration();

  // Clear cache tags.
  $this->cacheInvalidator
    ->invalidateTags($block
    ->getCacheTags());

  // Save block config.
  $this
    ->config('ds.field.' . $field['id'])
    ->set('properties.config', $block_config)
    ->save();

  // Clear caches and redirect.
  $this
    ->finishSubmitForm($form, $form_state);
}