summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/common.inc44
-rw-r--r--includes/form.inc5
-rw-r--r--includes/menu.inc5
3 files changed, 41 insertions, 13 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 63973c499..efa7d4728 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -1993,11 +1993,12 @@ function drupal_mail($mailkey, $to, $subject, $body, $from = NULL, $headers = ar
$defaults['From'] = $defaults['Reply-To'] = $defaults['Return-Path'] = $defaults['Errors-To'] = $from;
}
$headers = array_merge($defaults, $headers);
- // Custom hook traversal to allow pass by reference
- foreach (module_implements('mail_alter') AS $module) {
- $function = $module .'_mail_alter';
- $function($mailkey, $to, $subject, $body, $from, $headers);
- }
+
+ // Bundle up the variables into a structured array for altering.
+ $message = array('#mail_id' => $mailkey, '#to' => $to, '#subject' => $subject, '#body' => $body, '#from' => $from, '#headers' => $headers);
+ drupal_alter('mail', $message);
+ list($mailkey, $to, $subject, $body, $from, $headers) = $message;
+
// Allow for custom mail backend
if (variable_get('smtp_library', '') && file_exists(variable_get('smtp_library', ''))) {
include_once './' . variable_get('smtp_library', '');
@@ -2163,6 +2164,39 @@ function drupal_system_listing($mask, $directory, $key = 'name', $min_depth = 1)
return $files;
}
+
+/**
+ * This dispatch function hands off structured Drupal arrays to
+ * type-specific *_alter implementations. It ensures a consistent
+ * interface for all altering operations.
+ *
+ * @param $type
+ * The data type of the structured array. 'form', 'links',
+ * 'node_content', and so on are several examples.
+ * @param $data
+ * The structured array to be altered.
+ * @param ...
+ * Any additional params will be passed on to the called
+ * hook_$type_alter functions.
+ */
+function drupal_alter($type, &$data = array()) {
+ // Hang onto a reference to the data array so that it isn't blown away later.
+ $args = array(&$data);
+
+ // Now, use func_get_args() to pull in any aditional paramaters passed into
+ // the drupal_alter() call.
+ $aditional_args = func_get_args();
+ array_shift($aditional_args);
+ array_shift($aditional_args);
+ $args = array_merge($args, $aditional_args);
+
+ foreach (module_implements($type .'_alter') as $module) {
+ $function = $module .'_'. $type .'_alter';
+ call_user_func_array($function, $args);
+ }
+}
+
+
/**
* Renders HTML given a structured array tree. Recursively iterates over each
* of the array elements, generating HTML code. This function is usually
diff --git a/includes/form.inc b/includes/form.inc
index 49dc8e47a..f7d166f11 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -351,10 +351,7 @@ function drupal_prepare_form($form_id, &$form) {
}
}
- foreach (module_implements('form_alter') as $module) {
- $function = $module .'_form_alter';
- $function($form_id, $form);
- }
+ drupal_alter('form', $form, $form_id);
$form = form_builder($form_id, $form);
}
diff --git a/includes/menu.inc b/includes/menu.inc
index 1a2337ba9..435f694d4 100644
--- a/includes/menu.inc
+++ b/includes/menu.inc
@@ -552,10 +552,7 @@ function menu_rebuild() {
// TODO: split menu and menu links storage.
db_query('DELETE FROM {menu}');
$menu = module_invoke_all('menu');
- foreach (module_implements('menu_alter') as $module) {
- $function = $module .'_menu_alter';
- $function($menu);
- }
+ drupal_alter('menu', $menu);
$mid = 1;
// First pass: separate callbacks from pathes, making pathes ready for
// matching. Calculate fitness, and fill some default values.