You are here

public function LayoutParagraphsWidget::removeItemConfirmAjax in Layout Paragraphs 1.0.x

Ajax callback to remove an item - removes item from DOM.

Parameters

array $form: The form array.

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

Return value

\Drupal\Core\Ajax\AjaxResponse The Ajax Response

File

src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php, line 1931

Class

LayoutParagraphsWidget
Entity Reference with Layout field widget.

Namespace

Drupal\layout_paragraphs\Plugin\Field\FieldWidget

Code

public function removeItemConfirmAjax(array $form, FormStateInterface $form_state) {
  $element = $form_state
    ->getTriggeringElement();
  $uuid = $element['#uuid'];
  $parents = $element['#element_parents'];
  $field_state = static::getWidgetState($parents, $this->fieldName, $form_state);
  $html_id = $this
    ->entityFormHtmlId($field_state);
  $widget_field = NestedArray::getValue($form, $field_state['array_parents']);
  $disabled_bin = $widget_field['disabled'];
  $response = new AjaxResponse();
  $response
    ->addCommand(new RemoveCommand('.paragraph-' . $uuid));
  $response
    ->addCommand(new CloseDialogCommand('#' . $html_id));
  $response
    ->addCommand(new ReplaceCommand('#' . $this->wrapperId . ' .layout-paragraphs-disabled-items', $disabled_bin));
  $response
    ->addCommand(new SettingsCommand([
    'layoutParagraphsWidgets' => [
      $this->wrapperId => [
        'itemsCount' => $this
          ->activeItemsCount($field_state['items']),
      ],
    ],
  ], TRUE));
  return $response;
}