drupal_alter

Versions
6
drupal_alter($type, &$data)
7
drupal_alter($type, &$data, &$context1 = NULL, &$context2 = NULL)

Hands off alterable variables to type-specific *_alter implementations.

This dispatch function hands off the passed in variables to type-specific hook_TYPE_alter() implementations in modules. It ensures a consistent interface for all altering operations.

A maximum of 2 alterable arguments is supported. In case more arguments need to be passed and alterable, modules provide additional variables assigned by reference in the last $context argument:

<?php

$context = array(
'alterable' => &$alterable,
'unalterable' => $unalterable,
'foo' => 'bar',
);
drupal_alter('mymodule_data', $alterable1, $alterable2, $context);

?>

Note that objects are always passed by reference in PHP5. If it is absolutely required that no implementation alters a passed object in $context, then an object needs to be cloned:

<?php

$context = array(
'unalterable_object' => clone $object,
);
drupal_alter('mymodule_data', $data, $context);

?>

Parameters

$type A string describing the data type of the alterable $data. 'form', 'links', 'node_content', and so on are several examples.

&$data The primary data to be altered.

&$context1 (optional) An additional variable that is passed by reference.

&$context2 (optional) An additional variable that is passed by reference. If more context needs to be provided to implementations, then this should be an keyed array as described above.

▾ 63 functions call drupal_alter()

actions_list in includes/actions.inc
Discovers all available actions by invoking hook_action_info().
ajax_render in includes/ajax.inc
Render a commands array into JSON and exit.
archiver_get_info in includes/common.inc
Retrieve a list of all available archivers.
batch_process in includes/form.inc
Processes the batch.
comment_build in modules/comment/comment.module
Generate an array for rendering the given comment.
country_get_list in includes/locale.inc
Get list of all predefined and custom countries.
dashboard_region_descriptions in modules/dashboard/dashboard.module
Return an array of dashboard region descriptions, keyed by region name.
drupal_cron_run in includes/common.inc
Executes a cron run when called.
drupal_deliver_page in includes/common.inc
Deliver a page callback result to the browser in the format appropriate.
drupal_get_css in includes/common.inc
Returns a themed representation of all stylesheets that should be attached to the page.
drupal_get_html_head in includes/common.inc
Retrieve output to be displayed in the HEAD tag of the HTML page.
drupal_get_js in includes/common.inc
Returns a themed presentation of all JavaScript code for the current page.
drupal_get_library in includes/common.inc
Retrieves information for a JavaScript/CSS library.
drupal_get_schema in includes/bootstrap.inc
Get the schema definition of a table, or the whole database schema.
drupal_get_updaters in includes/common.inc
Drupal Updater registry.
drupal_goto in includes/common.inc
Send the user to a different Drupal page.
drupal_mail in includes/mail.inc
Compose and optionally send an e-mail message.
drupal_prepare_form in includes/form.inc
Prepares a structured form array by adding required elements, executing any hook_form_alter functions, and optionally inserting a validation token to prevent tampering.
drupal_render_page in includes/common.inc
Renders the page, including all theming.
element_info in includes/common.inc
Retrieve the default properties for the defined element type.
entity_get_info in includes/common.inc
Get the entity info array of an entity type.
field_attach_preprocess in modules/field/field.attach.inc
Populate the template variables with the field values available for rendering.
field_attach_view in modules/field/field.attach.inc
Generate and return a structured content array tree suitable for drupal_render() for all of the fields on an object. The format of each field's rendered content depends on the display formatter and its settings.
field_extra_fields in modules/field/field.module
Registry of pseudo-field components in a given bundle.
file_create_url in includes/file.inc
Creates a web-accessible URL for a stream to an external or local file.
file_get_stream_wrappers in includes/file.inc
Drupal stream wrapper registry.
file_mimetype_mapping in includes/file.mimetypes.inc
Return an array of MIME extension mappings.
filter_get_filters in modules/filter/filter.module
Return a list of all filters provided by modules.
format_username in includes/common.inc
Format a username.
image_styles in modules/image/image.module
Get an array of all styles and their settings.
language_fallback_get_candidates in includes/language.inc
Return the possible fallback languages ordered by language weight.
language_negotiation_get_switch_links in includes/language.inc
Return the language switch links for the given language.
language_negotiation_info in includes/language.inc
Return all the defined language providers.
language_types_info in includes/language.inc
Return all the defined language types.
menu_contextual_links in includes/menu.inc
Retrieve contextual links for a system object based on registered local tasks.
menu_execute_active_handler in includes/menu.inc
Execute the page callback associated with the current path.
menu_link_save in includes/menu.inc
Save a menu link.
menu_local_tasks in includes/menu.inc
Collects the local tasks (tabs), action links, and the root path.
menu_router_build in includes/menu.inc
Collect and alter the menu definitions.
node_access_acquire_grants in modules/node/node.module
This function will call module invoke to get a list of grants and then write them to the database. It is called at node save, and should be called by modules whenever something other than a node_save causes the permissions on a node to change.
node_access_grants in modules/node/node.module
Fetch an array of permission IDs granted to the given user ID.
node_build in modules/node/node.module
Generate an array for rendering the given node.
token_info in includes/token.inc
Returns metadata describing supported tokens.
trigger_assign in modules/trigger/trigger.admin.inc
Builds the form that allows users to assign actions to triggers.
trigger_menu in modules/trigger/trigger.module
Implement hook_menu().
update_calculate_project_data in modules/update/update.compare.inc
Given the installed projects and the available release data retrieved from remote servers, calculate the current status.
update_get_projects in modules/update/update.compare.inc
Fetch an array of installed and enabled projects.
upload_js in modules/upload/upload.module
Menu-callback for JavaScript-based uploads.
url in includes/common.inc
Generate a URL.
user_build in modules/user/user.module
Generate an array for rendering the given user.
user_cancel_methods in modules/user/user.pages.inc
Helper function to return available account cancellation methods.
_block_load_blocks in modules/block/block.module
Load blocks information from the database.
_block_render_blocks in modules/block/block.module
Render the content and subject for a set of blocks.
_field_info_collate_fields in modules/field/field.info.inc
Collate all information on existing fields and instances.
_field_info_collate_types in modules/field/field.info.inc
Collate all information on field types, widget types and related structures.
_menu_link_translate in includes/menu.inc
This function is similar to _menu_translate() but does link-specific preparation such as always calling to_arg functions
_registry_rebuild in includes/registry.inc
@see registry_rebuild.
_system_date_formats_build in modules/system/system.module
Builds and returns the list of available date formats.
_system_date_format_types_build in modules/system/system.module
Builds and returns the list of available date types.
_system_rebuild_module_data in modules/system/system.module
Helper function to scan and collect module .info data.
_system_rebuild_theme_data in modules/system/system.module
Helper function to scan and collect theme .info data and their engines.
_theme_build_registry in includes/theme.inc
Rebuild the theme registry cache.
_trigger_get_all_info in modules/trigger/trigger.module
Retrieves and caches information from hook_trigger_info() implementations.

Code

includes/common.inc, line 4748

<?php
function drupal_alter($type, &$data, &$context1 = NULL, &$context2 = NULL) {
  // Use the advanced drupal_static() pattern, since this is called very often.
  static $drupal_static = array();
  isset($drupal_static[__FUNCTION__]) || ($drupal_static[__FUNCTION__] = &drupal_static(__FUNCTION__));
  $functions = &$drupal_static[__FUNCTION__];

  // Some alter hooks are invoked many times per page request, so statically
  // cache the list of functions to call, and on subsequent calls, iterate
  // through them quickly.
  if (!isset($functions[$type])) {
    $functions[$type] = array();
    $hook = $type . '_alter';
    foreach (module_implements($hook) as $module) {
      $functions[$type][] = $module . '_' . $hook;
    }
    // Allow the theme to alter variables after the theme system has been
    // initialized.
    global $theme, $base_theme_info;
    if (isset($theme)) {
      $theme_keys = array();
      foreach ($base_theme_info as $base) {
        $theme_keys[] = $base->name;
      }
      $theme_keys[] = $theme;
      foreach ($theme_keys as $theme_key) {
        $function = $theme_key . '_' . $hook;
        if (function_exists($function)) {
          $functions[$type][] = $function;
        }
      }
    }
  }
  foreach ($functions[$type] as $function) {
    $function($data, $context1, $context2);
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.