- Patch #334030 by justinrandell: replace module_list with module_implements when calling a hook.

merge-requests/26/head
Dries Buytaert 2008-11-15 11:45:04 +00:00
parent 10104ba94a
commit 97fdc49191
7 changed files with 38 additions and 38 deletions

View File

@ -1220,19 +1220,18 @@ function menu_get_active_help() {
$arg = drupal_help_arg(arg(NULL)); $arg = drupal_help_arg(arg(NULL));
$empty_arg = drupal_help_arg(); $empty_arg = drupal_help_arg();
foreach (module_list() as $name) { foreach (module_implements('help') as $module) {
if (module_hook($name, 'help')) { $function = $module . '_help';
// Lookup help for this path. // Lookup help for this path.
if ($help = module_invoke($name, 'help', $router_path, $arg)) { if ($help = $function($router_path, $arg)) {
$output .= $help . "\n"; $output .= $help . "\n";
} }
// Add "more help" link on admin pages if the module provides a // Add "more help" link on admin pages if the module provides a
// standalone help page. // standalone help page.
if ($arg[0] == "admin" && module_exists('help') && module_invoke($name, 'help', 'admin/help#' . $arg[2], $empty_arg) && $help) { if ($arg[0] == "admin" && module_exists('help') && $function('admin/help#' . $arg[2], $empty_arg) && $help) {
$output .= theme("more_help_link", url('admin/help/' . $arg[2])); $output .= theme("more_help_link", url('admin/help/' . $arg[2]));
} }
} }
}
return $output; return $output;
} }

View File

@ -1945,8 +1945,8 @@ function _comment_update_node_statistics($nid) {
*/ */
function comment_invoke_comment(&$comment, $op) { function comment_invoke_comment(&$comment, $op) {
$return = array(); $return = array();
foreach (module_implements('comment') as $name) { foreach (module_implements('comment') as $module) {
$function = $name . '_comment'; $function = $module . '_comment';
$result = $function($comment, $op); $result = $function($comment, $op);
if (isset($result) && is_array($result)) { if (isset($result) && is_array($result)) {
$return = array_merge($return, $result); $return = array_merge($return, $result);

View File

@ -326,8 +326,9 @@ function filter_formats($index = NULL) {
function filter_list_all() { function filter_list_all() {
$filters = array(); $filters = array();
foreach (module_list() as $module) { foreach (module_implements('filter') as $module) {
$list = module_invoke($module, 'filter', 'list'); $function = $module . '_filter';
$list = $function('list');
if (isset($list) && is_array($list)) { if (isset($list) && is_array($list)) {
foreach ($list as $delta => $name) { foreach ($list as $delta => $name) {
$filters[$module . '/' . $delta] = (object)array('module' => $module, 'delta' => $delta, 'name' => $name); $filters[$module . '/' . $delta] = (object)array('module' => $module, 'delta' => $delta, 'name' => $name);

View File

@ -716,8 +716,8 @@ function node_invoke(&$node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) {
function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
$return = array(); $return = array();
$hook = 'nodeapi_' . $op; $hook = 'nodeapi_' . $op;
foreach (module_implements($hook) as $name) { foreach (module_implements($hook) as $module) {
$function = $name . '_' . $hook; $function = $module . '_' . $hook;
$result = $function($node, $a3, $a4); $result = $function($node, $a3, $a4);
if (isset($result) && is_array($result)) { if (isset($result) && is_array($result)) {
$return = array_merge($return, $result); $return = array_merge($return, $result);

View File

@ -37,13 +37,12 @@ function search_admin_settings() {
// Collect some stats // Collect some stats
$remaining = 0; $remaining = 0;
$total = 0; $total = 0;
foreach (module_list() as $module) { foreach (module_implements('search') as $module) {
if (module_hook($module, 'search')) { $function = $module . '_search';
$status = module_invoke($module, 'search', 'status'); $status = $function('status');
$remaining += $status['remaining']; $remaining += $status['remaining'];
$total += $status['total']; $total += $status['total'];
} }
}
$count = format_plural($remaining, 'There is 1 item left to index.', 'There are @count items left to index.'); $count = format_plural($remaining, 'There is 1 item left to index.', 'There are @count items left to index.');
$percentage = ((int)min(100, 100 * ($total - $remaining) / max(1, $total))) . '%'; $percentage = ((int)min(100, 100 * ($total - $remaining) / max(1, $total))) . '%';
$status = '<p><strong>' . t('%percentage of the site has been indexed.', array('%percentage' => $percentage)) . ' ' . $count . '</strong></p>'; $status = '<p><strong>' . t('%percentage of the site has been indexed.', array('%percentage' => $percentage)) . ' ' . $count . '</strong></p>';

View File

@ -208,14 +208,14 @@ function search_menu() {
'file path' => drupal_get_path('module', 'dblog'), 'file path' => drupal_get_path('module', 'dblog'),
); );
foreach (module_implements('search') as $name) { foreach (module_implements('search') as $module) {
$items['search/' . $name . '/%menu_tail'] = array( $items['search/' . $module . '/%menu_tail'] = array(
'title callback' => 'module_invoke', 'title callback' => 'module_invoke',
'title arguments' => array($name, 'search', 'name', TRUE), 'title arguments' => array($module, 'search', 'name', TRUE),
'page callback' => 'search_view', 'page callback' => 'search_view',
'page arguments' => array($name), 'page arguments' => array($module),
'access callback' => '_search_menu', 'access callback' => '_search_menu',
'access arguments' => array($name), 'access arguments' => array($module),
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
'parent' => 'search', 'parent' => 'search',
); );
@ -277,8 +277,9 @@ function search_cron() {
register_shutdown_function('search_update_totals'); register_shutdown_function('search_update_totals');
// Update word index // Update word index
foreach (module_list() as $module) { foreach (module_implements('update_index') as $module) {
module_invoke($module, 'update_index'); $function = $module . '_update_index';
$function();
} }
} }

View File

@ -23,13 +23,11 @@ define('EMAIL_MAX_LENGTH', 64);
* be passed by reference. * be passed by reference.
*/ */
function user_module_invoke($type, &$array, &$user, $category = NULL) { function user_module_invoke($type, &$array, &$user, $category = NULL) {
foreach (module_list() as $module) { foreach (module_implements('user_' . $type) as $module) {
$function = $module . '_user_' . $type; $function = $module . '_user_' . $type;
if (function_exists($function)) {
$function($array, $user, $category); $function($array, $user, $category);
} }
} }
}
/** /**
* Implementation of hook_theme(). * Implementation of hook_theme().
@ -1952,8 +1950,9 @@ function user_filters() {
} }
$options = array(); $options = array();
foreach (module_list() as $module) { foreach (module_implements('perm') as $module) {
if ($permissions = module_invoke($module, 'perm')) { $function = $module . '_perm';
if ($permissions = $function('perm')) {
asort($permissions); asort($permissions);
foreach ($permissions as $permission => $description) { foreach ($permissions as $permission => $description) {
$options[t('@module module', array('@module' => $module))][$permission] = t($permission); $options[t('@module module', array('@module' => $module))][$permission] = t($permission);
@ -2437,8 +2436,9 @@ function user_register_validate($form, &$form_state) {
*/ */
function _user_forms(&$edit, $account, $category, $hook = 'form') { function _user_forms(&$edit, $account, $category, $hook = 'form') {
$groups = array(); $groups = array();
foreach (module_list() as $module) { foreach (module_implements('user_' . $hook) as $module) {
if ($data = module_invoke($module, 'user_' . $hook, $edit, $account, $category)) { $function = $module . '_user_' . $hook;
if ($data = $function($edit, $account, $category)) {
$groups = array_merge_recursive($data, $groups); $groups = array_merge_recursive($data, $groups);
} }
} }