Commit 1bb684da authored by Vishal Khode's avatar Vishal Khode Committed by Jonathan Smith
Browse files

Issue #3312069 by vishalkhode, jonathan1055, DieterHolvoet:...

Issue #3312069 by vishalkhode, jonathan1055, DieterHolvoet: ModuleHandlerInterface::getImplementations() is deprecated in 9.4
parent a3a1d4ea
Loading
Loading
Loading
Loading
+12 −1
Changes for scheduler.module: 12 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -963,11 +963,22 @@ function scheduler_cron() {
  // Scheduler 7.x provided hook_scheduler_api() which has been replaced by
  // event dispatching in 8.x. Display a warning in the log if any of these
  // hooks still exist, so that admins and developers are informed.
  if (version_compare(\Drupal::VERSION, '9.4', '>=')) {
    // getImplementations() is deprecated in D9.4, use invokeAllWith().
    \Drupal::moduleHandler()->invokeAllWith('scheduler_api', function (callable $hook, string $module) {
      \Drupal::logger('scheduler')->warning('Function %function has not been executed. Implementations of hook_scheduler_api() should be replaced by Scheduler event listeners.', [
        '%function' => $module . '_scheduler_api',
      ]);
    });
  }
  else {
    // Use getImplementations() to maintain compatibility with Drupal 8.9.
    foreach (Drupal::moduleHandler()->getImplementations('scheduler_api') as $module) {
    \Drupal::logger('scheduler')->warning('Function %function has not been executed. In Drupal 8, implementations of hook_scheduler_api() should be replaced by Scheduler event listeners.', [
      \Drupal::logger('scheduler')->warning('Function %function has not been executed. Implementations of hook_scheduler_api() should be replaced by Scheduler event listeners.', [
        '%function' => $module . '_scheduler_api',
      ]);
    }
  }

  // Reset the static scheduler_cron flag.
  drupal_static_reset(__FUNCTION__);
+15 −7
Changes for src/SchedulerManager.php: 15 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -730,16 +730,24 @@ class SchedulerManager {
      $hooks[] = $legacy_node_hooks[$hookType];
    }

    // Get all modules that implement these hooks, then use array_walk to append
    // the $hook to the end of the module, thus giving the full function name.
    // Find all modules that implement these hooks, then append the $hookName to
    // the end of the module, thus giving the full function name.
    $all_hook_implementations = [];
    foreach ($hooks as $hook) {
      $hook = "scheduler_$hook";
      $implementations = $this->moduleHandler->getImplementations($hook);
      array_walk($implementations, function (&$item) use ($hook) {
        $item = $item . '_' . $hook;
      $hookName = "scheduler_$hook";
      if (version_compare(\Drupal::VERSION, '9.4', '>=')) {
        // getImplementations() is deprecated in D9.4, use invokeAllWith().
        $this->moduleHandler->invokeAllWith($hookName, function (callable $hook, string $module) use ($hookName, &$all_hook_implementations) {
          $all_hook_implementations[] = $module . "_" . $hookName;
        });
      $all_hook_implementations = array_merge($all_hook_implementations, $implementations);
      }
      else {
        // Use getImplementations() to maintain compatibility with Drupal 8.9.
        $implementations = $this->moduleHandler->getImplementations($hookName);
        array_walk($implementations, function (&$module) use ($hookName, &$all_hook_implementations) {
          $all_hook_implementations[] = $module . "_" . $hookName;
        });
      }
    }
    return $all_hook_implementations;
  }