You are here

public static function InlineParagraphsWidget::setSetSubmit in Paragraphs Sets 8

File

src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php, line 373

Class

InlineParagraphsWidget
Plugin definition of the 'entity_reference paragraphs sets' widget.

Namespace

Drupal\paragraphs_sets\Plugin\Field\FieldWidget

Code

public static function setSetSubmit(array $form, FormStateInterface $form_state) {
  $button = $form_state
    ->getTriggeringElement();

  // Go one level up in the form, to the widgets container.
  $element = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -2));
  $field_name = $element['#field_name'];
  $parents = $element['#field_parents'];
  $button_type = end($button['#array_parents']);

  // Increment the items count.
  $widget_state = static::getWidgetState($parents, $field_name, $form_state);
  $widget_state['button_type'] = $button_type;
  if (isset($button['#set_machine_name'])) {
    $widget_state['selected_set'] = $button['#set_machine_name'];
  }
  else {
    $widget_state['selected_set'] = $element['set_selection']['set_selection_select']['#value'];
  }
  static::setWidgetState($parents, $field_name, $form_state, $widget_state);
  $form_state
    ->setRebuild();
}