function views_ui_add_ajax_trigger

Same name and namespace in other branches
  1. 11.x core/modules/views_ui/admin.inc \views_ui_add_ajax_trigger()
  2. 10 core/modules/views_ui/admin.inc \views_ui_add_ajax_trigger()
  3. 9 core/modules/views_ui/admin.inc \views_ui_add_ajax_trigger()
  4. 8.9.x core/modules/views_ui/admin.inc \views_ui_add_ajax_trigger()

Converts a form element in the add view wizard to be AJAX-enabled.

This function takes a form element and adds AJAX behaviors to it such that changing it triggers another part of the form to update automatically. It also adds a submit button to the form that appears next to the triggering element and that duplicates its functionality for users who do not have JavaScript enabled (the button is automatically hidden for users who do have JavaScript).

To use this function, call it directly from your form builder function immediately after you have defined the form element that will serve as the JavaScript trigger. Calling it elsewhere (such as in hook_form_alter()) may mean that the non-JavaScript fallback button does not appear in the correct place in the form.

Parameters

array $wrapping_element: The element whose child will server as the AJAX trigger. For example, if $form['some_wrapper']['triggering_element'] represents the element which will trigger the AJAX behavior, you would pass $form['some_wrapper'] for this parameter.

string $trigger_key: The key within the wrapping element that identifies which of its children serves as the AJAX trigger. In the above example, you would pass 'triggering_element' for this parameter.

array $refresh_parents: An array of parent keys that point to the part of the form that will be refreshed by AJAX. For example, if triggering the AJAX behavior should cause $form['dynamic_content']['section'] to be refreshed, you would pass ['dynamic_content', 'section'] for this parameter.

Deprecated

in drupal:11.4.0 and is removed from drupal:13.0.0. There is no public replacement for this function. Form classes can use the protected method \Drupal\views\ViewsFormAjaxHelperTrait::addAjaxTrigger().

See also

https://www.drupal.org/node/3040111

File

core/modules/views_ui/admin.inc, line 49

Code

function views_ui_add_ajax_trigger(&$wrapping_element, $trigger_key, $refresh_parents) : void {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. There is no public replacement for this function. Form classes can use the protected method \\Drupal\\views_ui\\ViewsFormAjaxHelperTrait::addAjaxTrigger(). See https://www.drupal.org/node/3040111', E_USER_DEPRECATED);
  _views_ui_wrap_views_form_helper_traits()->addAjaxTriggerWrapper($wrapping_element, $trigger_key, $refresh_parents);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.