You are here

public function BlockFieldForm::submitForm in Display Suite 8.4

Same name and namespace in other branches
  1. 8.2 src/Form/BlockFieldForm.php \Drupal\ds\Form\BlockFieldForm::submitForm()
  2. 8.3 src/Form/BlockFieldForm.php \Drupal\ds\Form\BlockFieldForm::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/BlockFieldForm.php, line 107

Class

BlockFieldForm
Configure block fields.

Namespace

Drupal\ds\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  parent::submitForm($form, $form_state);

  // Create an instance of the block to find out if it has a config form.
  // Redirect to the block config form if there is one.

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

  // Inject default theme in form state (Site branding needs it for instance).
  $form_state = new FormState();
  $default_theme = $this
    ->config('system.theme')
    ->get('default');
  $form_state
    ->set('block_theme', $default_theme);
  $block_config_form = $block
    ->blockForm([], $form_state);
  if ($block_config_form) {
    $url = new Url('ds.manage_block_field_config', [
      'field_key' => $this->field['id'],
    ]);
    $form_state
      ->setRedirectUrl($url);
  }

  // Invalidate all blocks.
  Cache::invalidateTags([
    'config:ds.block_base',
  ]);
}