8.2.x form.api.php hook_ajax_render_alter(array &$data)
8.0.x form.api.php hook_ajax_render_alter(array &$data)
8.1.x form.api.php hook_ajax_render_alter(array &$data)
7.x system.api.php hook_ajax_render_alter(&$commands)

Alter the commands that are sent to the user through the Ajax framework.


$commands: An array of all commands that will be sent to the user.

See also


Related topics

1 invocation of hook_ajax_render_alter()
ajax_render in includes/ajax.inc
Renders a commands array into JSON.


modules/system/system.api.php, line 878
Hooks provided by Drupal core and the System module.


function hook_ajax_render_alter(&$commands) {
  // Inject any new status messages into the content area.
  $commands[] = ajax_command_prepend('#block-system-main .content', theme('status_messages'));


jhr’s picture

function mymodule_ajax_render_alter(&$commands) {
  $commands[] = ajax_command_alert('Winning!');
netgenius.co.uk’s picture

// Allow pop-up messages to be added to the AJAX commands.
function mymodule_ajax_render_alter(&$commands) {
  static $alerts = array();
  // If we are adding an alert message...
  if (is_string($commands)) {
    $alerts[] = $commands;
  // Else, this function is being called as a hook.
  // Insert alert messages to the $commands.
  else {
    foreach ($alerts as $alert) {
      $commands[] = ajax_command_alert($alert);

// Elsewhere in the module:
mymodule_ajax_render_alter($msg = 'Hi there');
mymodule_ajax_render_alter($msg = 'How is it going?');