Patched to Drupal 8.4.8 level. See https://www.drupal.org/sa-core-2018-004 and patch...
[yaffs-website] / web / core / lib / Drupal / Core / Queue / QueueWorkerManager.php
1 <?php
2
3 namespace Drupal\Core\Queue;
4
5 use Drupal\Core\Cache\CacheBackendInterface;
6 use Drupal\Core\Extension\ModuleHandlerInterface;
7 use Drupal\Core\Plugin\DefaultPluginManager;
8
9 /**
10  * Defines the queue worker manager.
11  *
12  * @see \Drupal\Core\Queue\QueueWorkerInterface
13  * @see \Drupal\Core\Queue\QueueWorkerBase
14  * @see \Drupal\Core\Annotation\QueueWorker
15  * @see plugin_api
16  */
17 class QueueWorkerManager extends DefaultPluginManager implements QueueWorkerManagerInterface {
18
19   /**
20    * Constructs an QueueWorkerManager object.
21    *
22    * @param \Traversable $namespaces
23    *   An object that implements \Traversable which contains the root paths
24    *   keyed by the corresponding namespace to look for plugin implementations.
25    * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
26    *   Cache backend instance to use.
27    * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
28    *   The module handler.
29    */
30   public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
31     parent::__construct('Plugin/QueueWorker', $namespaces, $module_handler, 'Drupal\Core\Queue\QueueWorkerInterface', 'Drupal\Core\Annotation\QueueWorker');
32
33     $this->setCacheBackend($cache_backend, 'queue_plugins');
34     $this->alterInfo('queue_info');
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   public function processDefinition(&$definition, $plugin_id) {
41     parent::processDefinition($definition, $plugin_id);
42
43     // Assign a default time if a cron is specified.
44     if (isset($definition['cron'])) {
45       $definition['cron'] += [
46         'time' => 15,
47       ];
48     }
49   }
50
51   /**
52    * {@inheritdoc}
53    *
54    * @return \Drupal\Core\Queue\QueueWorkerInterface
55    */
56   public function createInstance($plugin_id, array $configuration = []) {
57     return parent::createInstance($plugin_id, $configuration);
58   }
59
60 }