You are here

function views_ui_add_ajax_wrapper in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views_ui/admin.inc \views_ui_add_ajax_wrapper()

After-build function that adds a wrapper to a form region (for AJAX refreshes).

This function inserts a wrapper around the region of the form that needs to be refreshed by AJAX, based on information stored in the corresponding submit button form element.

1 string reference to 'views_ui_add_ajax_wrapper'
views_ui_add_ajax_trigger in core/modules/views_ui/admin.inc
Converts a form element in the add view wizard to be AJAX-enabled.

File

core/modules/views_ui/admin.inc, line 158
Provides the Views' administrative interface.

Code

function views_ui_add_ajax_wrapper($element, FormStateInterface $form_state) {

  // Find the region of the complete form that needs to be refreshed by AJAX.
  // This was earlier stored in a property on the element.
  $complete_form =& $form_state
    ->getCompleteForm();
  $refresh_parents = $element['#views_ui_ajax_data']['refresh_parents'];
  $refresh_element = NestedArray::getValue($complete_form, $refresh_parents);

  // The HTML ID that AJAX expects was also stored in a property on the
  // element, so use that information to insert the wrapper <div> here.
  $id = $element['#views_ui_ajax_data']['wrapper'];
  $refresh_element += [
    '#prefix' => '',
    '#suffix' => '',
  ];
  $refresh_element['#prefix'] = '<div id="' . $id . '" class="views-ui-ajax-wrapper">' . $refresh_element['#prefix'];
  $refresh_element['#suffix'] .= '</div>';

  // Copy the element that needs to be refreshed back into the form, with our
  // modifications to it.
  NestedArray::setValue($complete_form, $refresh_parents, $refresh_element);
  return $element;
}