From 383c0d0fdfc7de055e7b40dbd7f67b476ffc3c50 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sun, 10 Jan 2021 18:01:20 +0000 Subject: [PATCH] Push to IFTTT References #328 --- .../QueueWorker/PostPusherQueueWorker.php | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/web/modules/custom/blog/src/Plugin/QueueWorker/PostPusherQueueWorker.php b/web/modules/custom/blog/src/Plugin/QueueWorker/PostPusherQueueWorker.php index 0bd6244..ac050de 100644 --- a/web/modules/custom/blog/src/Plugin/QueueWorker/PostPusherQueueWorker.php +++ b/web/modules/custom/blog/src/Plugin/QueueWorker/PostPusherQueueWorker.php @@ -8,6 +8,8 @@ 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\PostPusher; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -21,15 +23,22 @@ final class PostPusherQueueWorker extends QueueWorkerBase implements ContainerFa private EntityStorageInterface $nodeStorage; + /** + * @var array|PostPusher[] + */ + private array $postPushers; + public function __construct( array $configuration, string $pluginId, array $pluginDefinition, - EntityStorageInterface $nodeStorage + EntityStorageInterface $nodeStorage, + array $postPushers ) { parent::__construct($configuration, $pluginId, $pluginDefinition); $this->nodeStorage = $nodeStorage; + $this->postPushers = $postPushers; } public static function create( @@ -42,7 +51,10 @@ final class PostPusherQueueWorker extends QueueWorkerBase implements ContainerFa $configuration, $pluginId, $pluginDefinition, - $container->get('entity_type.manager')->getStorage('node') + $container->get('entity_type.manager')->getStorage('node'), + [ + $container->get(IftttPostPusher::class), + ] ); } @@ -63,6 +75,11 @@ final class PostPusherQueueWorker extends QueueWorkerBase implements ContainerFa } } + foreach ($this->postPushers as $pusher) { + // @phpstan-ignore-next-line + $pusher->push($post); + } + // @phpstan-ignore-next-line $post->set(Post::FIELD_SENT_TO_SOCIAL_MEDIA, TRUE); $post->save();