Commit 0382e78b authored by voleger's avatar voleger
Browse files

Add correct implementation of DI

parent 76a6cd9e
name: Queue order [no UI]
name: "Queue order"
type: module
description: "Provide api to control queue order execution"
package: System utility
description: "Provide basic functionality to control queue order execution"
package: "System utility"
core: 8.x
dependencies:
- drupal:system (>= 8.2.0)
- drupal:system
......@@ -3,6 +3,9 @@
namespace Drupal\queue_order\Queue;
use Drupal\Component\Utility\SortArray;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Queue\QueueWorkerManager as CoreQueueWorkerManager;
/**
......@@ -12,12 +15,37 @@ use Drupal\Core\Queue\QueueWorkerManager as CoreQueueWorkerManager;
*/
class QueueWorkerManager extends CoreQueueWorkerManager {
/**
* The module config.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* Constructs an QueueWorkerManager object.
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
* The module configs.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config) {
parent::__construct($namespaces, $cache_backend, $module_handler);
$this->config = $config->get('queue_order.settings');
}
/**
* {@inheritdoc}
*/
public function getDefinitions() {
$definitions = parent::getDefinitions();
$weight = \Drupal::config('queue_order.settings')->get('order');
$weight = $this->config->get('order');
$weight = empty($weight) ? [] : $weight;
foreach ($definitions as $key => &$definition) {
$definition['weight'] = empty($weight[$key]) ? 0 : intval($weight[$key]);
......
......@@ -5,6 +5,7 @@ namespace Drupal\queue_order;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;
use Drupal\queue_order\Queue\QueueWorkerManager;
use Symfony\Component\DependencyInjection\Reference;
/**
* Class QueueOrderServiceProvider.
......@@ -18,8 +19,9 @@ class QueueOrderServiceProvider extends ServiceProviderBase {
*/
public function alter(ContainerBuilder $container) {
if ($container->has('plugin.manager.queue_worker')) {
$container->getDefinition('plugin.manager.queue_worker')
->setClass(QueueWorkerManager::class);
$plugin_manager = $container->getDefinition('plugin.manager.queue_worker');
$plugin_manager->setClass(QueueWorkerManager::class);
$plugin_manager->addArgument(new Reference('config.factory'));
}
}
......
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