You are here

public static function WebformAjaxElementTrait::updateAjaxElementCallback in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Element/WebformAjaxElementTrait.php \Drupal\webform\Element\WebformAjaxElementTrait::updateAjaxElementCallback()

Ajax element update callback.

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array The properties element.

File

src/Element/WebformAjaxElementTrait.php, line 187

Class

WebformAjaxElementTrait
Trait for ajax element support.

Namespace

Drupal\webform\Element

Code

public static function updateAjaxElementCallback(array $form, FormStateInterface $form_state) {
  $button = $form_state
    ->getTriggeringElement();
  $id = $button['#webform_ajax_element_id'];

  // Check if the immediate parent element is the Ajax wrapper.
  $element = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -1));
  if (isset($element['#webform_ajax_element_id']) && $element['#webform_ajax_element_id'] === $id && isset($element['#webform_type']) && $element['#webform_type'] === 'wrapper') {
    return $element;
  }

  // Get the Ajax wrapper from the parent parent element.
  $parent_element = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -2));
  return static::getAjaxElementWrapperRecursive($id, $parent_element);
}