Issue #2045921 by juanolalla, Xano, Sutharsan, InternetDevels: Replace all module_invoke() deprecated function calls.
parent
85a75d43bf
commit
98cdbfec7b
|
@ -1865,25 +1865,6 @@ function module_implements($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.
|
||||
*
|
||||
|
|
|
@ -2775,7 +2775,7 @@ function drupal_get_library($module, $name = NULL) {
|
|||
|
||||
if (!isset($libraries[$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)) {
|
||||
$module_libraries = array();
|
||||
}
|
||||
|
|
|
@ -660,7 +660,7 @@ function drupal_install_system($install_state) {
|
|||
->save();
|
||||
}
|
||||
|
||||
module_invoke('system', 'install');
|
||||
\Drupal::moduleHandler()->invoke('system', 'install');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1012,7 +1012,7 @@ function drupal_requirements_severity(&$requirements) {
|
|||
function drupal_check_module($module) {
|
||||
module_load_install($module);
|
||||
// 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) {
|
||||
// Print any error messages
|
||||
foreach ($requirements as $requirement) {
|
||||
|
|
|
@ -151,8 +151,9 @@ function drupal_mail($module, $key, $to, $langcode, $params = array(), $reply =
|
|||
$message['headers'] = $headers;
|
||||
|
||||
// Build the e-mail (get subject and body, allow additional headers) by
|
||||
// invoking hook_mail() on this module. We cannot use module_invoke() as
|
||||
// we need to have $message by reference in hook_mail().
|
||||
// invoking hook_mail() on this module. We cannot use
|
||||
// moduleHandler()->invoke() as we need to have $message by reference in
|
||||
// hook_mail().
|
||||
if (function_exists($function = $module . '_mail')) {
|
||||
$function($key, $message, $params);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
// would cause array_merge() to set the $schema variable to NULL as well.
|
||||
// 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,
|
||||
// as they needlessly slow down cache()->get() for every single request.
|
||||
_drupal_schema_initialize($current, $module);
|
||||
|
@ -268,7 +268,7 @@ function drupal_uninstall_schema($module) {
|
|||
function drupal_get_schema_unprocessed($module, $table = NULL) {
|
||||
// Load the .install file to get hook_schema.
|
||||
module_load_install($module);
|
||||
$schema = module_invoke($module, 'schema');
|
||||
$schema = \Drupal::moduleHandler()->invoke($module, 'schema');
|
||||
|
||||
if (isset($table)) {
|
||||
if (isset($schema[$table])) {
|
||||
|
|
|
@ -426,9 +426,9 @@ function update_get_update_list() {
|
|||
// Otherwise, get the list of updates defined by this module.
|
||||
$updates = drupal_get_schema_versions($module);
|
||||
if ($updates !== FALSE) {
|
||||
// module_invoke returns NULL for nonexisting hooks, so if no updates
|
||||
// are removed, it will == 0.
|
||||
$last_removed = module_invoke($module, 'update_last_removed');
|
||||
// \Drupal::moduleHandler()->invoke() returns NULL for nonexisting hooks,
|
||||
// so if no updates are removed, it will == 0.
|
||||
$last_removed = \Drupal::moduleHandler()->invoke($module, 'update_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.';
|
||||
continue;
|
||||
|
|
|
@ -652,7 +652,7 @@ function file_file_download($uri, $field_type = 'file') {
|
|||
// Default to FALSE and let entities overrule this ruling.
|
||||
$grants = array('system' => FALSE);
|
||||
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.
|
||||
$context = array(
|
||||
|
|
|
@ -102,7 +102,7 @@ class NodeFormController extends ContentEntityFormController {
|
|||
'#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(
|
||||
'#title' => t('Language'),
|
||||
'#type' => 'language_select',
|
||||
|
|
|
@ -429,7 +429,7 @@ function _search_index_truncate(&$text) {
|
|||
*/
|
||||
function search_invoke_preprocess(&$text, $langcode = NULL) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {
|
||||
\Drupal::moduleHandler()->install(array('module_test'), FALSE);
|
||||
$this->resetAll();
|
||||
$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().');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2888,7 +2888,7 @@ function system_get_module_admin_tasks($module, $info) {
|
|||
|
||||
$admin_tasks = 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) {
|
||||
if (isset($links[$machine_name])) {
|
||||
$task = $links[$machine_name];
|
||||
|
|
|
@ -96,7 +96,7 @@ function module_test_menu() {
|
|||
* @deprecated \Drupal\module_test\Controller\ModuleTestController::hookDynamicLoadingInvoke()
|
||||
*/
|
||||
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'];
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ class Permission extends AccessPluginBase {
|
|||
|
||||
// Get list of permissions
|
||||
foreach (\Drupal::moduleHandler()->getImplementations('permission') as $module) {
|
||||
$permissions = module_invoke($module, 'permission');
|
||||
$permissions = \Drupal::moduleHandler()->invoke($module, 'permission');
|
||||
foreach ($permissions as $name => $perm) {
|
||||
$perms[$module_info[$module]['name']][$name] = strip_tags($perm['title']);
|
||||
}
|
||||
|
|
|
@ -1564,7 +1564,7 @@ function user_role_load($rid) {
|
|||
function user_permission_get_modules() {
|
||||
$permissions = array();
|
||||
foreach (\Drupal::moduleHandler()->getImplementations('permission') as $module) {
|
||||
$perms = module_invoke($module, 'permission');
|
||||
$perms = \Drupal::moduleHandler()->invoke($module, 'permission');
|
||||
foreach ($perms as $key => $value) {
|
||||
$permissions[$key] = $module;
|
||||
}
|
||||
|
@ -1797,7 +1797,7 @@ function user_modules_installed($modules) {
|
|||
if ($rid) {
|
||||
$permissions = array();
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue