? .DS_Store
? alter.patch
? index.html
? sites/alter
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.619
diff -u -p -r1.619 common.inc
--- includes/common.inc 8 Mar 2007 19:33:55 -0000 1.619
+++ includes/common.inc 24 Mar 2007 22:49:41 -0000
@@ -1993,11 +1993,12 @@ function drupal_mail($mailkey, $to, $sub
$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);
+ $message = 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,41 @@ function drupal_system_listing($mask, $d
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.
+ * @return
+ * The altered version of the $data array.
+ */
+function drupal_alter($type, $data = array()) {
+ $args = func_get_args();
+ // Strip out the first arg, because it's already in $type.
+ array_shift($args);
+
+ // PHP 4 doesn't allow us to pass references using call_user_func_array(), so
+ // we need to use a 'real' copy of the $data array. Each time we pass through
+ // the loop, we put the freshly altered copy of $data back into $args for the
+ // next hook_$type_alter implementation to work with.
+ foreach (module_implements($type .'_alter') as $module) {
+ $function = $module .'_'. $type .'_alter';
+ $args[0] = $data;
+ $data = call_user_func_array($function, $args);
+ }
+ return $data;
+}
+
+
/**
* Renders HTML given a structured array tree. Recursively iterates over each
* of the array elements, generating HTML code. This function is usually
Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.182
diff -u -p -r1.182 form.inc
--- includes/form.inc 17 Mar 2007 18:30:14 -0000 1.182
+++ includes/form.inc 24 Mar 2007 22:49:42 -0000
@@ -351,10 +351,7 @@ function drupal_prepare_form($form_id, &
}
}
- foreach (module_implements('form_alter') as $module) {
- $function = $module .'_form_alter';
- $function($form_id, $form);
- }
+ $form = drupal_alter('form', $form, $form_id);
$form = form_builder($form_id, $form);
}
Index: modules/color/color.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/color/color.module,v
retrieving revision 1.15
diff -u -p -r1.15 color.module
--- modules/color/color.module 20 Jan 2007 08:12:20 -0000 1.15
+++ modules/color/color.module 24 Mar 2007 22:49:43 -0000
@@ -4,7 +4,7 @@
/**
* Implementation of hook_form_alter().
*/
-function color_form_alter($form_id, &$form) {
+function color_form_alter($form, $form_id) {
// Insert the color changer into the theme settings page.
// TODO: Last condition in the following if disables color changer when private files are used this should be solved in a different way. See issue #92059.
if ($form_id == 'system_theme_settings' && color_get_info(arg(4)) && function_exists('gd_info') && variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC) {
@@ -30,6 +30,7 @@ function color_form_alter($form_id, &$fo
}
}
}
+ return $form;
}
/**
Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.529
diff -u -p -r1.529 comment.module
--- modules/comment/comment.module 12 Mar 2007 13:08:02 -0000 1.529
+++ modules/comment/comment.module 24 Mar 2007 22:49:45 -0000
@@ -374,7 +374,7 @@ function comment_link($type, $node = NUL
return $links;
}
-function comment_form_alter($form_id, &$form) {
+function comment_form_alter($form, $form_id) {
if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
$form['workflow']['comment'] = array(
'#type' => 'radios',
@@ -403,6 +403,7 @@ function comment_form_alter($form_id, &$
);
}
}
+ return $form;
}
/**
@@ -963,11 +964,7 @@ function comment_render($node, $cid = 0)
if ($comment = db_fetch_object($result)) {
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
$links = module_invoke_all('link', 'comment', $comment, 1);
-
- foreach (module_implements('link_alter') as $module) {
- $function = $module .'_link_alter';
- $function($node, $links);
- }
+ $links = drupal_alter('link', $links, $node);
$output .= theme('comment_view', $comment, $links);
}
Index: modules/forum/forum.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/forum/forum.module,v
retrieving revision 1.387
diff -u -p -r1.387 forum.module
--- modules/forum/forum.module 17 Mar 2007 18:30:14 -0000 1.387
+++ modules/forum/forum.module 24 Mar 2007 22:49:47 -0000
@@ -207,7 +207,7 @@ function forum_admin_settings() {
/**
* Implementation of hook_form_alter().
*/
-function forum_form_alter($form_id, &$form) {
+function forum_form_alter($form, $form_id) {
// hide critical options from forum vocabulary
if ($form_id == 'taxonomy_form_vocabulary') {
if ($form['vid']['#value'] == _forum_get_vid()) {
@@ -226,6 +226,7 @@ function forum_form_alter($form_id, &$fo
unset($form['nodes']['forum']);
}
}
+ return $form;
}
/**
@@ -657,7 +658,7 @@ function _forum_parent_select($tid, $tit
return array('#type' => 'select', '#title' => $title, '#default_value' => $parent, '#options' => $options, '#description' => $description, '#required' => TRUE);
}
-function forum_link_alter(&$node, &$links) {
+function forum_link_alter($links, $node) {
foreach ($links as $module => $link) {
if (strstr($module, 'taxonomy_term')) {
// Link back to the forum and not the taxonomy term page. We'll only
@@ -669,6 +670,7 @@ function forum_link_alter(&$node, &$link
}
}
}
+ return $links;
}
/**
Index: modules/menu/menu.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/menu/menu.module,v
retrieving revision 1.103
diff -u -p -r1.103 menu.module
--- modules/menu/menu.module 17 Mar 2007 18:30:14 -0000 1.103
+++ modules/menu/menu.module 24 Mar 2007 22:49:49 -0000
@@ -172,7 +172,7 @@ function menu_perm() {
* Implementation of hook_form_alter().
* Add menu item fields to the node form.
*/
-function menu_form_alter($form_id, &$form) {
+function menu_form_alter($form, $form_id) {
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
$item = array();
if ($form['nid']['#value'] > 0) {
@@ -242,6 +242,7 @@ function menu_form_alter($form_id, &$for
);
}
}
+ return $form;
}
/**
Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.791
diff -u -p -r1.791 node.module
--- modules/node/node.module 17 Mar 2007 18:30:14 -0000 1.791
+++ modules/node/node.module 24 Mar 2007 22:49:57 -0000
@@ -673,11 +673,7 @@ function node_view($node, $teaser = FALS
if ($links) {
$node->links = module_invoke_all('link', 'node', $node, !$page);
-
- foreach (module_implements('link_alter') AS $module) {
- $function = $module .'_link_alter';
- $function($node, $node->links);
- }
+ $node->links = drupal_alter('link', $node->links, $node);
}
// Set the proper node part, then unset unused $node part so that a bad
@@ -2456,7 +2452,7 @@ function node_update_index() {
/**
* Implementation of hook_form_alter().
*/
-function node_form_alter($form_id, &$form) {
+function node_form_alter($form, $form_id) {
// Advanced node search form
if ($form_id == 'search_form' && $form['module']['#value'] == 'node' && user_access('use advanced search')) {
// Keyword boxes:
@@ -2521,6 +2517,7 @@ function node_form_alter($form_id, &$for
$form['#validate']['node_search_validate'] = array();
}
+ return $form;
}
/**
Index: modules/path/path.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/path/path.module,v
retrieving revision 1.110
diff -u -p -r1.110 path.module
--- modules/path/path.module 17 Mar 2007 18:30:14 -0000 1.110
+++ modules/path/path.module 24 Mar 2007 22:49:57 -0000
@@ -267,7 +267,7 @@ function path_nodeapi(&$node, $op, $arg)
/**
* Implementation of hook_form_alter().
*/
-function path_form_alter($form_id, &$form) {
+function path_form_alter($form, $form_id) {
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
$path = isset($form['#node']->path) ? $form['#node']->path : NULL;
$form['path'] = array(
@@ -293,6 +293,7 @@ function path_form_alter($form_id, &$for
);
}
}
+ return $form;
}
Index: modules/taxonomy/taxonomy.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v
retrieving revision 1.341
diff -u -p -r1.341 taxonomy.module
--- modules/taxonomy/taxonomy.module 27 Feb 2007 12:48:33 -0000 1.341
+++ modules/taxonomy/taxonomy.module 24 Mar 2007 22:50:00 -0000
@@ -39,10 +39,7 @@ function taxonomy_link($type, $node = NU
}
// We call this hook again because some modules and themes call taxonomy_link('taxonomy terms') directly
- foreach (module_implements('link_alter') as $module) {
- $function = $module .'_link_alter';
- $function($node, $links);
- }
+ $links = drupal_alter('link', $links, $node);
return $links;
}
@@ -655,7 +652,7 @@ function taxonomy_get_vocabularies($type
* Implementation of hook_form_alter().
* Generate a form for selecting terms to associate with a node.
*/
-function taxonomy_form_alter($form_id, &$form) {
+function taxonomy_form_alter( $form, $form_id) {
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
$node = $form['#node'];
@@ -727,6 +724,7 @@ function taxonomy_form_alter($form_id, &
$form['taxonomy']['#tree'] = TRUE;
}
}
+ return $form;
}
/**
Index: modules/upload/upload.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/upload/upload.module,v
retrieving revision 1.154
diff -u -p -r1.154 upload.module
--- modules/upload/upload.module 6 Mar 2007 16:43:10 -0000 1.154
+++ modules/upload/upload.module 24 Mar 2007 22:50:01 -0000
@@ -333,7 +333,7 @@ function _upload_prepare(&$node) {
}
}
-function upload_form_alter($form_id, &$form) {
+function upload_form_alter($form, $form_id) {
if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
$form['workflow']['upload'] = array(
'#type' => 'radios',
@@ -388,6 +388,7 @@ function upload_form_alter($form_id, &$f
}
}
}
+ return $form;
}
function _upload_validate(&$node) {
@@ -883,10 +884,7 @@ function upload_js() {
_upload_validate($node);
$form = _upload_form($node);
- foreach (module_implements('form_alter') as $module) {
- $function = $module .'_form_alter';
- $function('upload_js', $form);
- }
+ $form = drupal_alter('form', $form, 'upload_js');
$form = form_builder('upload_js', $form);
$output = theme('status_messages') . drupal_render($form);
// We send the updated file attachments form.
Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.760
diff -u -p -r1.760 user.module
--- modules/user/user.module 24 Mar 2007 05:36:30 -0000 1.760
+++ modules/user/user.module 24 Mar 2007 22:50:05 -0000
@@ -1605,13 +1605,7 @@ function user_view($account) {
}
}
- // Let modules change the returned fields - useful for personal privacy
- // controls. Since modules communicate changes by reference, we cannot use
- // module_invoke_all().
- foreach (module_implements('profile_alter') as $module) {
- $function = $module .'_profile_alter';
- $function($account, $fields);
- }
+ $fields = drupal_alter('profile', $fields, $account);
drupal_set_title(check_plain($account->name));
return theme('user_profile', $account, $fields);