diff --git a/web/modules/custom/blog/opdavies_blog.services.yml b/web/modules/custom/blog/opdavies_blog.services.yml index 5e696332..d7a721c3 100644 --- a/web/modules/custom/blog/opdavies_blog.services.yml +++ b/web/modules/custom/blog/opdavies_blog.services.yml @@ -1,5 +1,8 @@ parameters: container.autowiring.strict_mode: true + opdavies_blog.post_pushers: + - '@Drupal\opdavies_blog\Service\PostPusher\IftttPostPusher' + - '@Drupal\opdavies_blog\Service\PostPusher\IntegromatPostPusher' services: Drupal\Core\Config\ConfigFactoryInterface: diff --git a/web/modules/custom/blog/src/Plugin/QueueWorker/PostPusherQueueWorker.php b/web/modules/custom/blog/src/Plugin/QueueWorker/PostPusherQueueWorker.php index eb42b2be..1af227c4 100644 --- a/web/modules/custom/blog/src/Plugin/QueueWorker/PostPusherQueueWorker.php +++ b/web/modules/custom/blog/src/Plugin/QueueWorker/PostPusherQueueWorker.php @@ -4,12 +4,11 @@ namespace Drupal\opdavies_blog\Plugin\QueueWorker; +use Assert\Assertion; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Queue\QueueWorkerBase; use Drupal\opdavies_blog\Entity\Node\Post; -use Drupal\opdavies_blog\Service\PostPusher\IftttPostPusher; -use Drupal\opdavies_blog\Service\PostPusher\IntegromatPostPusher; use Drupal\opdavies_blog\Service\PostPusher\PostPusher; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -48,15 +47,22 @@ public static function create( $pluginId, $pluginDefinition ) { + $postPushers = []; + + foreach ($container->getParameter('opdavies_blog.post_pushers') as $postPusher) { + Assertion::isInstanceOf($postPusher, '\stdClass'); + Assertion::eq($postPusher->type, 'service'); + Assertion::notEmpty($postPusher->id); + + $postPushers[] = $container->get($postPusher->id); + } + return new static( $configuration, $pluginId, $pluginDefinition, $container->get('entity_type.manager')->getStorage('node'), - [ - $container->get(IftttPostPusher::class), - $container->get(IntegromatPostPusher::class), - ] + $postPushers ); }