1 system.api.php hook_page_delivery_callback_alter(&$callback)

Alters the delivery callback used to send the result of the page callback to the browser.

Called by backdrop_deliver_page() to allow modules to alter how the page is delivered to the browser.

This hook is intended for altering the delivery callback based on information unrelated to the path of the page accessed. For example, it can be used to set the delivery callback based on a HTTP request header (as shown in the code sample). To specify a delivery callback based on path information, use hook_menu() or hook_menu_alter().

This hook can also be used as an API function that can be used to explicitly set the delivery callback from some other function. For example, for a module named MODULE:

function MODULE_page_delivery_callback_alter(&$callback, $set = FALSE) {
  static $stored_callback;
  if ($set) {
    $stored_callback = $callback;
  elseif (isset($stored_callback)) {
    $callback = $stored_callback;
function SOMEWHERE_ELSE() {
  $desired_delivery_callback = 'foo';
  MODULE_page_delivery_callback_alter($desired_delivery_callback, TRUE);


$callback: The name of a function.

See also


Related topics


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


function hook_page_delivery_callback_alter(&$callback) {
  // jQuery sets a HTTP_X_REQUESTED_WITH header of 'XMLHttpRequest'.
  // If a page would normally be delivered as an html page, and it is called
  // from jQuery, deliver it instead as an Ajax response.
  if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' && $callback == 'backdrop_deliver_html_page') {
    $callback = 'ajax_deliver';