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;
}
doc_Drupal
2016-10-29 09:55:41
Comments
Leave a Comment

Please login to continue.