You are here

protected function BlockStyleForm::successfulAjaxSubmit in Block Style Plugins 8.2

Allows the form to respond to a successful AJAX submission.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

\Drupal\Core\Ajax\AjaxResponse An AJAX response.

Overrides AjaxFormHelperTrait::successfulAjaxSubmit

File

src/Form/BlockStyleForm.php, line 214

Class

BlockStyleForm
Provides a form for applying styles to a block.

Namespace

Drupal\block_style_plugins\Form

Code

protected function successfulAjaxSubmit(array $form, FormStateInterface $form_state) {
  $style_id = $form_state
    ->getValue('block_styles');
  $parameters = $this
    ->getParameters($style_id);
  $new_form = $this->formBuilder
    ->getForm('\\Drupal\\block_style_plugins\\Form\\ConfigureStyles', $this->sectionStorage, $parameters['delta'], $parameters['uuid'], $parameters['plugin_id']);
  $url = new Url('block_style_plugins.layout_builder.add_styles', $parameters, [
    'query' => [
      FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
      '_wrapper_format' => 'drupal_ajax',
    ],
  ]);
  $new_form['actions']['submit']['#attached']['drupalSettings']['ajax'][$new_form['actions']['submit']['#id']]['url'] = $url
    ->toString();
  $response = new AjaxResponse();
  $response
    ->addCommand(new OpenOffCanvasDialogCommand($this
    ->t('Configure Styles'), $new_form));
  return $response;
}