summaryrefslogtreecommitdiff
path: root/modules/system
diff options
context:
space:
mode:
Diffstat (limited to 'modules/system')
-rw-r--r--modules/system/system.api.php74
-rw-r--r--modules/system/system.install15
-rw-r--r--modules/system/system.module12
3 files changed, 99 insertions, 2 deletions
diff --git a/modules/system/system.api.php b/modules/system/system.api.php
index d2a2bffcd..8826e6a08 100644
--- a/modules/system/system.api.php
+++ b/modules/system/system.api.php
@@ -2507,5 +2507,79 @@ function hook_date_formats_alter(&$formats) {
}
/**
+ * Alters the router item for the active menu handler.
+ *
+ * Called by menu_execute_active_handler() to allow modules to alter the
+ * information that will be used to handle the page request. Only use this
+ * hook if an alteration specific to the page request is needed. Otherwise
+ * use hook_menu_alter().
+ *
+ * @param $router_item
+ * An array with the following keys:
+ * - access: Boolean. Whether the user is allowed to see this page.
+ * - file: A path to a file to include prior to invoking the page callback.
+ * - page_callback: The function to call to build the page content.
+ * - page_arguments: Arguments to pass to the page callback.
+ * - delivery_callback: The function to call to deliver the result of the
+ * page callback to the browser.
+ * @param $path
+ * The drupal path that was used for retrieving the router item.
+ *
+ * @see menu_execute_active_handler()
+ * @see hook_menu()
+ * @see hook_menu_alter()
+ */
+function hook_menu_active_handler_alter(&$router_item, $path = NULL) {
+ // Turn off access for all pages for all users.
+ $router_item['access'] = FALSE;
+}
+
+/**
+ * Alters the delivery callback used to send the result of the page callback to the browser.
+ *
+ * Called by drupal_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(), hook_menu_alter() or
+ * hook_menu_active_handler_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:
+ * @code
+ * 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);
+ * }
+ * @endcode
+ *
+ * @param $callback
+ * The name of a function.
+ *
+ * @see drupal_deliver_page()
+ */
+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 == 'drupal_deliver_html_page') {
+ $callback = 'ajax_deliver';
+ }
+}
+
+/**
* @} End of "addtogroup hooks".
*/
diff --git a/modules/system/system.install b/modules/system/system.install
index 47bc3a968..3c3fc0c71 100644
--- a/modules/system/system.install
+++ b/modules/system/system.install
@@ -1005,6 +1005,13 @@ function system_schema() {
'type' => 'text',
'not null' => FALSE,
),
+ 'delivery_callback' => array(
+ 'description' => 'The name of the function that sends the result of the page_callback function to the browser.',
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => TRUE,
+ 'default' => '',
+ ),
'fit' => array(
'description' => 'A numeric representation of how specific the path is.',
'type' => 'int',
@@ -2726,6 +2733,14 @@ function system_update_7040() {
}
/**
+ * Adds 'delivery_callback' field to the {menu_router} table to allow a custom
+ * function to be used for final page rendering and sending to browser.
+ */
+function system_update_7041() {
+ db_add_field('menu_router', 'delivery_callback', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
+}
+
+/**
* @} End of "defgroup updates-6.x-to-7.x"
* The next series of updates should start at 8000.
*/
diff --git a/modules/system/system.module b/modules/system/system.module
index 98ceebc0f..70c789f8b 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -314,6 +314,13 @@ function system_element_info() {
'#attributes' => array(),
'#items' => array(),
);
+ // By default, we don't want AJAX commands being rendered in the context of an
+ // HTML page, so we don't provide defaults for #theme or #theme_wrappers.
+ // However, modules can set these properties (for example, to provide an HTML
+ // debugging page that displays rather than executes AJAX commands).
+ $types['ajax_commands'] = array(
+ '#ajax_commands' => array(),
+ );
// Input elements.
$types['submit'] = array(
@@ -499,6 +506,7 @@ function system_menu() {
$items['system/ajax'] = array(
'title' => 'AHAH callback',
'page callback' => 'ajax_form_callback',
+ 'delivery callback' => 'ajax_deliver',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
'file path' => 'includes',
@@ -1752,7 +1760,7 @@ function system_admin_menu_block($item) {
$default_task = NULL;
$has_subitems = FALSE;
$result = db_query("
- SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.theme_callback, m.theme_arguments, m.type, m.description, m.path, m.weight as router_weight, ml.*
+ SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.delivery_callback, m.title, m.title_callback, m.title_arguments, m.theme_callback, m.theme_arguments, m.type, m.description, m.path, m.weight as router_weight, ml.*
FROM {menu_router} m
LEFT JOIN {menu_links} ml ON m.path = ml.router_path
WHERE (ml.plid = :plid AND ml.menu_name = :name AND hidden = 0) OR (m.tab_parent = :path AND m.type IN (:local_task, :default_task))", array(':plid' => $item['mlid'], ':name' => $item['menu_name'], ':path' => $item['path'], ':local_task' => MENU_LOCAL_TASK, ':default_task' => MENU_DEFAULT_LOCAL_TASK), array('fetch' => PDO::FETCH_ASSOC));
@@ -2468,7 +2476,7 @@ function system_get_module_admin_tasks($module) {
if (empty($items)) {
$result = db_query("
- SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.theme_callback, m.theme_arguments, m.type, ml.*
+ SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.delivery_callback, m.title, m.title_callback, m.title_arguments, m.theme_callback, m.theme_arguments, m.type, ml.*
FROM {menu_links} ml INNER JOIN {menu_router} m ON ml.router_path = m.path WHERE ml.link_path LIKE 'admin/%' AND hidden >= 0 AND module = 'system' AND m.number_parts > 2", array(), array('fetch' => PDO::FETCH_ASSOC));
foreach ($result as $item) {
_menu_link_translate($item);