Commit 769bd1f9 authored by catch's avatar catch

Issue #2055371 by ianthomas_uk, Xano, InternetDevels, alexpott: Replace all...

Issue #2055371 by ianthomas_uk, Xano, InternetDevels, alexpott: Replace all module_invoke_all() deprecated function calls in OO code.
parent 14cae9d1
......@@ -389,9 +389,9 @@ public function save(EntityInterface $entity) {
*/
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));
}
/**
......
......@@ -113,7 +113,7 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang
}
// 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 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la
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.
......
......@@ -160,7 +160,7 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $
// 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));
}
}
......
......@@ -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 @@ public static function getInfo() {
*/
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 @@ public function testLocks() {
}
}
}
namespace {
if (!function_exists('module_invoke_all')) {
function module_invoke_all() {}
}
}
......@@ -72,7 +72,7 @@ public function __construct(array $values, $entity_type) {
// 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;
}
......
......@@ -308,7 +308,7 @@ public function getHighestWeight() {
}
// 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;
}
......
......@@ -182,7 +182,7 @@ public function disable() {
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();
......
......@@ -331,7 +331,7 @@ public function validate(array $form, array &$form_state) {
}
// 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';
......
......@@ -15,7 +15,8 @@
*
* 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 {
......
......@@ -622,7 +622,7 @@ protected function checkPermissions(array $permissions, $reset = FALSE) {
$available = &drupal_static(__FUNCTION__);
if (!isset($available) || $reset) {
$available = array_keys(module_invoke_all('permission'));
$available = array_keys(\Drupal::moduleHandler()->invokeAll('permission'));
}
$valid = TRUE;
......
......@@ -37,7 +37,7 @@ public static function getInfo() {
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);
......
......@@ -128,13 +128,13 @@ function testModuleInvoke() {
}
/**
* 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().');
}
/**
......
......@@ -36,7 +36,7 @@ function setUp() {
// 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',
......
......@@ -44,7 +44,7 @@ public function alterRouteDefinition(Route $route) {
}
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'];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment