You are here

public static function ComponentSectionForm::variantButtonAjax in Module Builder 8.3

Ajax callback for the variant buttons.

This returns the new page content to replace the page content made obsolete by the form submission.

File

src/Form/ComponentSectionForm.php, line 822

Class

ComponentSectionForm
Generic form for entering a section of data for a component.

Namespace

Drupal\module_builder\Form

Code

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

  // Go up in the form, to the widgets container.
  $button_array_parents = $button['#array_parents'];

  // Get the address of the containing multiple data item.
  // WARNING: this assumes the 'data' form element is at the top in the
  // form structure!
  $widgets_container_parents = array_slice($button_array_parents, 0, -1);
  $element = NestedArray::getValue($form, $widgets_container_parents);
  return $element;
}