You are here

public function InsertComponentForm::successfulAjaxSubmit in Layout Paragraphs 2.0.x

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/InsertComponentForm.php, line 134

Class

InsertComponentForm
Class InsertComponentForm.

Namespace

Drupal\layout_paragraphs\Form

Code

public function successfulAjaxSubmit(array $form, FormStateInterface $form_state) {
  $response = new AjaxResponse();
  $this
    ->ajaxCloseForm($response);
  if ($this
    ->needsRefresh()) {
    return $this
      ->refreshLayout($response);
  }
  $uuid = $this->paragraph
    ->uuid();
  $rendered_item = $this
    ->renderParagraph($uuid);
  switch ($this->method) {
    case 'before':
      $response
        ->addCommand(new BeforeCommand($this->domSelector, $rendered_item));
      break;
    case 'after':
      $response
        ->addCommand(new AfterCommand($this->domSelector, $rendered_item));
      break;
    case 'append':
      $response
        ->addCommand(new AppendCommand($this->domSelector, $rendered_item));
      break;
    case 'prepend':
      $response
        ->addCommand(new PrependCommand($this->domSelector, $rendered_item));
      break;
  }
  $response
    ->addCommand(new LayoutParagraphsEventCommand($this->layoutParagraphsLayout, $uuid, 'component:insert'));
  return $response;
}