Issue #2055371 by ianthomas_uk, Xano, InternetDevels, alexpott: Replace all module_invoke_all() deprecated function calls in OO code.

8.0.x
Nathaniel Catchpole 2014-02-20 12:00:34 +00:00
parent 14cae9d115
commit 769bd1f946
14 changed files with 20 additions and 25 deletions

View File

@ -389,9 +389,9 @@ class ConfigStorageController extends EntityStorageControllerBase implements Con
*/
protected function invokeHook($hook, EntityInterface $entity) {
// Invoke the hook.
module_invoke_all($this->entityTypeId . '_' . $hook, $entity);
$this->moduleHandler->invokeAll($this->entityTypeId . '_' . $hook, array($entity));
// Invoke the respective entity-level hook.
module_invoke_all('entity_' . $hook, $entity, $this->entityTypeId);
$this->moduleHandler->invokeAll('entity_' . $hook, array($entity, $this->entityTypeId));
}
/**

View File

@ -113,7 +113,7 @@ class EntityViewBuilder extends EntityControllerBase implements EntityController
}
// Invoke hook_entity_prepare_view().
module_invoke_all('entity_prepare_view', $this->entityTypeId, $entities, $displays, $view_mode);
\Drupal::moduleHandler()->invokeAll('entity_prepare_view', array($this->entityTypeId, $entities, $displays, $view_mode));
// Let the displays build their render arrays.
foreach ($entities_by_bundle as $bundle => $bundle_entities) {
@ -225,8 +225,8 @@ class EntityViewBuilder extends EntityControllerBase implements EntityController
foreach ($entities as $key => $entity) {
$entity_view_mode = isset($entity->content['#view_mode']) ? $entity->content['#view_mode'] : $view_mode;
$display = $displays[$entity_view_mode][$entity->bundle()];
module_invoke_all($view_hook, $entity, $display, $entity_view_mode, $langcode);
module_invoke_all('entity_view', $entity, $display, $entity_view_mode, $langcode);
\Drupal::moduleHandler()->invokeAll($view_hook, array($entity, $display, $entity_view_mode, $langcode));
\Drupal::moduleHandler()->invokeAll('entity_view', array($entity, $display, $entity_view_mode, $langcode));
$build[$key] = $entity->content;
// We don't need duplicate rendering info in $entity->content.

View File

@ -160,7 +160,7 @@ class Comment extends ContentEntityBase implements CommentInterface {
// Update the {comment_entity_statistics} table prior to executing the hook.
$storage_controller->updateEntityStatistics($this);
if ($this->isPublished()) {
module_invoke_all('comment_publish', $this);
\Drupal::moduleHandler()->invokeAll('comment_publish', array($this));
}
}

View File

@ -4,7 +4,7 @@
* Contains \Drupal\comment\Tests\Entity\CommentTest
*/
namespace Drupal\comment\Tests\Entity {
namespace Drupal\comment\Tests\Entity;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
@ -33,6 +33,7 @@ class CommentLockTest extends UnitTestCase {
*/
public function testLocks() {
$container = new ContainerBuilder();
$container->set('module_handler', $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'));
$container->set('current_user', $this->getMock('Drupal\Core\Session\AccountInterface'));
$container->register('request', 'Symfony\Component\HttpFoundation\Request');
$lock = $this->getMock('Drupal\Core\Lock\LockBackendInterface');
@ -82,10 +83,3 @@ class CommentLockTest extends UnitTestCase {
}
}
}
namespace {
if (!function_exists('module_invoke_all')) {
function module_invoke_all() {}
}
}

View File

@ -72,7 +72,7 @@ class Editor extends ConfigEntityBase implements EditorInterface {
// Initialize settings, merging module-provided defaults.
$default_settings = $plugin->getDefaultSettings();
$default_settings += module_invoke_all('editor_default_settings', $this->editor);
$default_settings += \Drupal::moduleHandler()->invokeAll('editor_default_settings', array($this->editor));
drupal_alter('editor_default_settings', $default_settings, $this->editor);
$this->settings += $default_settings;
}

View File

@ -308,7 +308,7 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
}
// Let other modules feedback about their own additions.
$weights = array_merge($weights, module_invoke_all('field_info_max_weight', $this->targetEntityType, $this->bundle, $this->displayContext, $this->mode));
$weights = array_merge($weights, \Drupal::moduleHandler()->invokeAll('field_info_max_weight', array($this->targetEntityType, $this->bundle, $this->displayContext, $this->mode)));
return $weights ? max($weights) : NULL;
}

View File

@ -182,7 +182,7 @@ class FilterFormat extends ConfigEntityBase implements FilterFormatInterface {
parent::disable();
// Allow modules to react on text format deletion.
module_invoke_all('filter_format_disable', $this);
\Drupal::moduleHandler()->invokeAll('filter_format_disable', array($this));
// Clear the filter cache whenever a text format is disabled.
filter_formats_reset();

View File

@ -331,7 +331,7 @@ class NodeFormController extends ContentEntityFormController {
}
// Invoke hook_node_validate() for validation needed by modules.
// Can't use module_invoke_all(), because $form_state must
// Can't use \Drupal::moduleHandler()->invokeAll(), because $form_state must
// be receivable by reference.
foreach (\Drupal::moduleHandler()->getImplementations('node_validate') as $module) {
$function = $module . '_node_validate';

View File

@ -15,7 +15,8 @@ use Drupal\Core\Database\ConnectionNotDefinedException;
*
* These tests can not access the database nor files. Calling any Drupal
* function that needs the database will throw exceptions. These include
* watchdog(), \Drupal::moduleHandler()->getImplementations(), module_invoke_all() etc.
* watchdog(), \Drupal::moduleHandler()->getImplementations(),
* \Drupal::moduleHandler()->invokeAll() etc.
*/
abstract class UnitTestBase extends TestBase {

View File

@ -622,7 +622,7 @@ abstract class WebTestBase extends TestBase {
$available = &drupal_static(__FUNCTION__);
if (!isset($available) || $reset) {
$available = array_keys(module_invoke_all('permission'));
$available = array_keys(\Drupal::moduleHandler()->invokeAll('permission'));
}
$valid = TRUE;

View File

@ -37,7 +37,7 @@ class BreadcrumbTest extends MenuTestBase {
function setUp() {
parent::setUp();
$perms = array_keys(module_invoke_all('permission'));
$perms = array_keys(\Drupal::moduleHandler()->invokeAll('permission'));
$this->admin_user = $this->drupalCreateUser($perms);
$this->drupalLogin($this->admin_user);

View File

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

View File

@ -36,7 +36,7 @@ class AdminTest extends WebTestBase {
// Create an administrator with all permissions, as well as a regular user
// who can only access administration pages and perform some Locale module
// administrative tasks, but not all of them.
$this->admin_user = $this->drupalCreateUser(array_keys(module_invoke_all('permission')));
$this->admin_user = $this->drupalCreateUser(array_keys(\Drupal::moduleHandler()->invokeAll('permission')));
$this->web_user = $this->drupalCreateUser(array(
'access administration pages',
'translate interface',

View File

@ -44,7 +44,7 @@ class Permission extends AccessPluginBase {
}
public function summaryTitle() {
$permissions = module_invoke_all('permission');
$permissions = \Drupal::moduleHandler()->invokeAll('permission');
if (isset($permissions[$this->options['perm']])) {
return $permissions[$this->options['perm']]['title'];
}