You are here

public static function ParagraphsWidget::getSubmitElementInfo in Paragraphs 8

Get common submit element information for processing ajax submit handlers.

Parameters

array $form: Form array.

FormStateInterface $form_state: Form state object.

int $position: Position of triggering element.

Return value

array Submit element information.

10 calls to ParagraphsWidget::getSubmitElementInfo()
ParagraphsWidget::addMoreAjax in src/Plugin/Field/FieldWidget/ParagraphsWidget.php
Ajax callback for the "Add another item" button.
ParagraphsWidget::addMoreSubmit in src/Plugin/Field/FieldWidget/ParagraphsWidget.php
Submission handler for the "Add another item" button.
ParagraphsWidget::allActionsAjax in src/Plugin/Field/FieldWidget/ParagraphsWidget.php
Ajax callback for all actions.
ParagraphsWidget::changeAllEditModeSubmit in src/Plugin/Field/FieldWidget/ParagraphsWidget.php
Loops through all paragraphs and change mode for each paragraph instance.
ParagraphsWidget::dragDropModeAjax in src/Plugin/Field/FieldWidget/ParagraphsWidget.php
Ajax callback for the dragdrop mode.

... See full list

File

src/Plugin/Field/FieldWidget/ParagraphsWidget.php, line 1537

Class

ParagraphsWidget
Plugin implementation of the 'entity_reference_revisions paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

public static function getSubmitElementInfo(array $form, FormStateInterface $form_state, $position = ParagraphsWidget::ACTION_POSITION_BASE) {
  $submit['button'] = $form_state
    ->getTriggeringElement();

  // Go up in the form, to the widgets container.
  if ($position == ParagraphsWidget::ACTION_POSITION_BASE) {
    $submit['element'] = NestedArray::getValue($form, array_slice($submit['button']['#array_parents'], 0, -2));
  }
  if ($position == ParagraphsWidget::ACTION_POSITION_HEADER) {
    $submit['element'] = NestedArray::getValue($form, array_slice($submit['button']['#array_parents'], 0, -3));
  }
  elseif ($position == ParagraphsWidget::ACTION_POSITION_ACTIONS) {
    $submit['element'] = NestedArray::getValue($form, array_slice($submit['button']['#array_parents'], 0, -5));
    $delta = array_slice($submit['button']['#array_parents'], -5, -4);
    $submit['delta'] = $delta[0];
  }
  $submit['field_name'] = $submit['element']['#field_name'];
  $submit['parents'] = $submit['element']['#field_parents'];

  // Get widget state.
  $submit['widget_state'] = static::getWidgetState($submit['parents'], $submit['field_name'], $form_state);
  return $submit;
}