You are here

public static function HookImplementations::enqueueWarmers in Warmer 8

Same name and namespace in other branches
  1. 2.x src/HookImplementations.php \Drupal\warmer\HookImplementations::enqueueWarmers()

Helper function to implement hook_cron.

1 call to HookImplementations::enqueueWarmers()
warmer_cron in ./warmer.module
Implements hook_cron().

File

src/HookImplementations.php, line 16

Class

HookImplementations
Helper functions to use in hook implementations.

Namespace

Drupal\warmer

Code

public static function enqueueWarmers() {

  /** @var \Drupal\warmer\Plugin\WarmerPluginManager $warmer_manager */
  $warmer_manager = \Drupal::service('plugin.manager.warmer');

  // Instantiate all the plugin managers.
  $warmer_definitions = $warmer_manager
    ->getDefinitions();
  $warmers = array_map(function ($warmer_definition) use ($warmer_manager) {
    try {
      return $warmer_manager
        ->createInstance($warmer_definition['id']);
    } catch (PluginException $exception) {
      return NULL;
    }
  }, $warmer_definitions);

  /** @var \Drupal\warmer\Plugin\WarmerPluginBase[] $warmers */
  $warmers = array_filter($warmers, function ($warmer) {
    return $warmer instanceof WarmerPluginBase;
  });
  $warmers = array_filter($warmers, function (WarmerPluginBase $warmer) {
    return $warmer
      ->isActive();
  });
  $queue_manager = \Drupal::service('warmer.queue_manager');
  array_map(function (WarmerPluginBase $warmer) use ($queue_manager) {
    static::singleWarmer($warmer, $queue_manager);
  }, $warmers);
}