You are here

function _button_field_ajax_response in Button Field 8

Same name and namespace in other branches
  1. 7 button_field.module \_button_field_ajax_response()

Builds the response for an ajax callback.

1 call to _button_field_ajax_response()
button_field_callback_ajax in ./button_field.module
Callback function for the FAPI ajax framework, used on edit forms.

File

./button_field.module, line 63
Defines a field, widget and formatter for the button field type.

Code

function _button_field_ajax_response() {
  $response = new AjaxResponse();
  $container = \Drupal::getContainer();
  $request = $container
    ->get('request_stack')
    ->getCurrentRequest();
  $rules_path = $request->attributes
    ->get('_rules_redirect_action_url');
  if (!empty($rules_path)) {

    // Remove the redirect so that we don't return an HTML response, and add an
    // ajax redirect command.
    $request->attributes
      ->remove('_rules_redirect_action_url');
    $response
      ->addCommand(new RedirectCommand($rules_path));
  }
  return $response;
}