function views_ui_add_ajax_wrapper

views_ui_add_ajax_wrapper($element, FormStateInterface $form_state)

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.

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 += array(
    '#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;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!views_ui!admin.inc/function/views_ui_add_ajax_wrapper/8.1.x