Issue #2045921 by juanolalla, Xano, Sutharsan, InternetDevels: Replace all module_invoke() deprecated function calls.

8.0.x
Alex Pott 2014-02-13 10:53:00 +00:00
parent 85a75d43bf
commit 98cdbfec7b
14 changed files with 22 additions and 39 deletions

View File

@ -1865,25 +1865,6 @@ function module_implements($hook) {
return \Drupal::moduleHandler()->getImplementations($hook); return \Drupal::moduleHandler()->getImplementations($hook);
} }
/**
* Invokes a hook in a particular module.
*
* All arguments are passed by value. Use drupal_alter() if you need to pass
* arguments by reference.
*
* @deprecated as of Drupal 8.0. Use
* \Drupal::moduleHandler()->invoke($module, $hook, $args = array()).
*
* @see drupal_alter()
* @see \Drupal\Core\Extension\ModuleHandler::invoke()
*/
function module_invoke($module, $hook) {
$args = func_get_args();
// Remove $module and $hook from the arguments.
unset($args[0], $args[1]);
return \Drupal::moduleHandler()->invoke($module, $hook, $args);
}
/** /**
* Invokes a hook in all enabled modules that implement it. * Invokes a hook in all enabled modules that implement it.
* *

View File

@ -2775,7 +2775,7 @@ function drupal_get_library($module, $name = NULL) {
if (!isset($libraries[$module])) { if (!isset($libraries[$module])) {
// Retrieve all libraries associated with the module. // Retrieve all libraries associated with the module.
$module_libraries = module_invoke($module, 'library_info'); $module_libraries = \Drupal::moduleHandler()->invoke($module, 'library_info');
if (empty($module_libraries)) { if (empty($module_libraries)) {
$module_libraries = array(); $module_libraries = array();
} }

View File

@ -660,7 +660,7 @@ function drupal_install_system($install_state) {
->save(); ->save();
} }
module_invoke('system', 'install'); \Drupal::moduleHandler()->invoke('system', 'install');
} }
/** /**
@ -1012,7 +1012,7 @@ function drupal_requirements_severity(&$requirements) {
function drupal_check_module($module) { function drupal_check_module($module) {
module_load_install($module); module_load_install($module);
// Check requirements // Check requirements
$requirements = module_invoke($module, 'requirements', 'install'); $requirements = \Drupal::moduleHandler()->invoke($module, 'requirements', array('install'));
if (is_array($requirements) && drupal_requirements_severity($requirements) == REQUIREMENT_ERROR) { if (is_array($requirements) && drupal_requirements_severity($requirements) == REQUIREMENT_ERROR) {
// Print any error messages // Print any error messages
foreach ($requirements as $requirement) { foreach ($requirements as $requirement) {

View File

@ -151,8 +151,9 @@ function drupal_mail($module, $key, $to, $langcode, $params = array(), $reply =
$message['headers'] = $headers; $message['headers'] = $headers;
// Build the e-mail (get subject and body, allow additional headers) by // Build the e-mail (get subject and body, allow additional headers) by
// invoking hook_mail() on this module. We cannot use module_invoke() as // invoking hook_mail() on this module. We cannot use
// we need to have $message by reference in hook_mail(). // moduleHandler()->invoke() as we need to have $message by reference in
// hook_mail().
if (function_exists($function = $module . '_mail')) { if (function_exists($function = $module . '_mail')) {
$function($key, $message, $params); $function($key, $message, $params);
} }

View File

@ -80,7 +80,7 @@ function drupal_get_complete_schema($rebuild = FALSE) {
// Cast the result of hook_schema() to an array, as a NULL return value // Cast the result of hook_schema() to an array, as a NULL return value
// would cause array_merge() to set the $schema variable to NULL as well. // would cause array_merge() to set the $schema variable to NULL as well.
// That would break modules which use $schema further down the line. // That would break modules which use $schema further down the line.
$current = (array) module_invoke($module, 'schema'); $current = (array) \Drupal::moduleHandler()->invoke($module, 'schema');
// Set 'module' and 'name' keys for each table, and remove descriptions, // Set 'module' and 'name' keys for each table, and remove descriptions,
// as they needlessly slow down cache()->get() for every single request. // as they needlessly slow down cache()->get() for every single request.
_drupal_schema_initialize($current, $module); _drupal_schema_initialize($current, $module);
@ -268,7 +268,7 @@ function drupal_uninstall_schema($module) {
function drupal_get_schema_unprocessed($module, $table = NULL) { function drupal_get_schema_unprocessed($module, $table = NULL) {
// Load the .install file to get hook_schema. // Load the .install file to get hook_schema.
module_load_install($module); module_load_install($module);
$schema = module_invoke($module, 'schema'); $schema = \Drupal::moduleHandler()->invoke($module, 'schema');
if (isset($table)) { if (isset($table)) {
if (isset($schema[$table])) { if (isset($schema[$table])) {

View File

@ -426,9 +426,9 @@ function update_get_update_list() {
// Otherwise, get the list of updates defined by this module. // Otherwise, get the list of updates defined by this module.
$updates = drupal_get_schema_versions($module); $updates = drupal_get_schema_versions($module);
if ($updates !== FALSE) { if ($updates !== FALSE) {
// module_invoke returns NULL for nonexisting hooks, so if no updates // \Drupal::moduleHandler()->invoke() returns NULL for nonexisting hooks,
// are removed, it will == 0. // so if no updates are removed, it will == 0.
$last_removed = module_invoke($module, 'update_last_removed'); $last_removed = \Drupal::moduleHandler()->invoke($module, 'update_last_removed');
if ($schema_version < $last_removed) { if ($schema_version < $last_removed) {
$ret[$module]['warning'] = '<em>' . $module . '</em> module cannot be updated. Its schema version is ' . $schema_version . '. Updates up to and including ' . $last_removed . ' have been removed in this release. In order to update <em>' . $module . '</em> module, you will first <a href="http://drupal.org/upgrade">need to upgrade</a> to the last version in which these updates were available.'; $ret[$module]['warning'] = '<em>' . $module . '</em> module cannot be updated. Its schema version is ' . $schema_version . '. Updates up to and including ' . $last_removed . ' have been removed in this release. In order to update <em>' . $module . '</em> module, you will first <a href="http://drupal.org/upgrade">need to upgrade</a> to the last version in which these updates were available.';
continue; continue;

View File

@ -652,7 +652,7 @@ function file_file_download($uri, $field_type = 'file') {
// Default to FALSE and let entities overrule this ruling. // Default to FALSE and let entities overrule this ruling.
$grants = array('system' => FALSE); $grants = array('system' => FALSE);
foreach (\Drupal::moduleHandler()->getImplementations('file_download_access') as $module) { foreach (\Drupal::moduleHandler()->getImplementations('file_download_access') as $module) {
$grants = array_merge($grants, array($module => module_invoke($module, 'file_download_access', $field, $entity, $file))); $grants = array_merge($grants, array($module => \Drupal::moduleHandler()->invoke($module, 'file_download_access', array($field, $entity, $file))));
} }
// Allow other modules to alter the returned grants/denies. // Allow other modules to alter the returned grants/denies.
$context = array( $context = array(

View File

@ -102,7 +102,7 @@ class NodeFormController extends ContentEntityFormController {
'#default_value' => $node->getChangedTime(), '#default_value' => $node->getChangedTime(),
); );
$language_configuration = module_invoke('language', 'get_default_configuration', 'node', $node->getType()); $language_configuration = \Drupal::moduleHandler()->invoke('language', 'get_default_configuration', array('node', $node->getType()));
$form['langcode'] = array( $form['langcode'] = array(
'#title' => t('Language'), '#title' => t('Language'),
'#type' => 'language_select', '#type' => 'language_select',

View File

@ -429,7 +429,7 @@ function _search_index_truncate(&$text) {
*/ */
function search_invoke_preprocess(&$text, $langcode = NULL) { function search_invoke_preprocess(&$text, $langcode = NULL) {
foreach (\Drupal::moduleHandler()->getImplementations('search_preprocess') as $module) { foreach (\Drupal::moduleHandler()->getImplementations('search_preprocess') as $module) {
$text = module_invoke($module, 'search_preprocess', $text, $langcode); $text = \Drupal::moduleHandler()->invoke($module, 'search_preprocess', array($text, $langcode));
} }
} }

View File

@ -117,13 +117,14 @@ class ModuleApiTest extends WebTestBase {
} }
/** /**
* Test that module_invoke() can load a hook defined in hook_hook_info(). * Test that moduleHandler()->invoke() can load a hook defined in
* hook_hook_info().
*/ */
function testModuleInvoke() { function testModuleInvoke() {
\Drupal::moduleHandler()->install(array('module_test'), FALSE); \Drupal::moduleHandler()->install(array('module_test'), FALSE);
$this->resetAll(); $this->resetAll();
$this->drupalGet('module-test/hook-dynamic-loading-invoke'); $this->drupalGet('module-test/hook-dynamic-loading-invoke');
$this->assertText('success!', 'module_invoke() dynamically loads a hook defined in hook_hook_info().'); $this->assertText('success!', 'moduleHandler()->invoke() dynamically loads a hook defined in hook_hook_info().');
} }
/** /**

View File

@ -2888,7 +2888,7 @@ function system_get_module_admin_tasks($module, $info) {
$admin_tasks = array(); $admin_tasks = array();
$titles = array(); $titles = array();
if ($menu = module_invoke($module, 'menu_link_defaults')) { if ($menu = \Drupal::moduleHandler()->invoke($module, 'menu_link_defaults')) {
foreach ($menu as $machine_name => $item) { foreach ($menu as $machine_name => $item) {
if (isset($links[$machine_name])) { if (isset($links[$machine_name])) {
$task = $links[$machine_name]; $task = $links[$machine_name];

View File

@ -96,7 +96,7 @@ function module_test_menu() {
* @deprecated \Drupal\module_test\Controller\ModuleTestController::hookDynamicLoadingInvoke() * @deprecated \Drupal\module_test\Controller\ModuleTestController::hookDynamicLoadingInvoke()
*/ */
function module_test_hook_dynamic_loading_invoke() { function module_test_hook_dynamic_loading_invoke() {
$result = module_invoke('module_test', 'test_hook'); $result = \Drupal::moduleHandler()->invoke('module_test', 'test_hook');
return $result['module_test']; return $result['module_test'];
} }

View File

@ -67,7 +67,7 @@ class Permission extends AccessPluginBase {
// Get list of permissions // Get list of permissions
foreach (\Drupal::moduleHandler()->getImplementations('permission') as $module) { foreach (\Drupal::moduleHandler()->getImplementations('permission') as $module) {
$permissions = module_invoke($module, 'permission'); $permissions = \Drupal::moduleHandler()->invoke($module, 'permission');
foreach ($permissions as $name => $perm) { foreach ($permissions as $name => $perm) {
$perms[$module_info[$module]['name']][$name] = strip_tags($perm['title']); $perms[$module_info[$module]['name']][$name] = strip_tags($perm['title']);
} }

View File

@ -1564,7 +1564,7 @@ function user_role_load($rid) {
function user_permission_get_modules() { function user_permission_get_modules() {
$permissions = array(); $permissions = array();
foreach (\Drupal::moduleHandler()->getImplementations('permission') as $module) { foreach (\Drupal::moduleHandler()->getImplementations('permission') as $module) {
$perms = module_invoke($module, 'permission'); $perms = \Drupal::moduleHandler()->invoke($module, 'permission');
foreach ($perms as $key => $value) { foreach ($perms as $key => $value) {
$permissions[$key] = $module; $permissions[$key] = $module;
} }
@ -1797,7 +1797,7 @@ function user_modules_installed($modules) {
if ($rid) { if ($rid) {
$permissions = array(); $permissions = array();
foreach ($modules as $module) { foreach ($modules as $module) {
if ($module_permissions = module_invoke($module, 'permission')) { if ($module_permissions = \Drupal::moduleHandler()->invoke($module, 'permission')) {
$permissions = array_merge($permissions, array_keys($module_permissions)); $permissions = array_merge($permissions, array_keys($module_permissions));
} }
} }