You are here

public static function ParagraphsSets::setSetSubmit in Paragraphs Sets 8.2

File

src/ParagraphsSets.php, line 241

Class

ParagraphsSets
Utitlity class for paragraphs_sets.

Namespace

Drupal\paragraphs_sets

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();
}