diff --git a/web/modules/custom/blog/src/Plugin/QueueWorker/PostPusherQueueWorker.php b/web/modules/custom/blog/src/Plugin/QueueWorker/PostPusherQueueWorker.php index ac050de..ddc0ac6 100644 --- a/web/modules/custom/blog/src/Plugin/QueueWorker/PostPusherQueueWorker.php +++ b/web/modules/custom/blog/src/Plugin/QueueWorker/PostPusherQueueWorker.php @@ -9,6 +9,7 @@ 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; @@ -54,6 +55,7 @@ final class PostPusherQueueWorker extends QueueWorkerBase implements ContainerFa $container->get('entity_type.manager')->getStorage('node'), [ $container->get(IftttPostPusher::class), + $container->get(IntegromatPostPusher::class), ] ); } diff --git a/web/modules/custom/blog/src/Service/PostPusher/IntegromatPostPusher.php b/web/modules/custom/blog/src/Service/PostPusher/IntegromatPostPusher.php new file mode 100644 index 0000000..86436b4 --- /dev/null +++ b/web/modules/custom/blog/src/Service/PostPusher/IntegromatPostPusher.php @@ -0,0 +1,43 @@ +configFactory = $configFactory; + + parent::__construct($client); + } + + public function push(Post $post): void { + $url = $this->configFactory + ->get('opdavies_blog.settings') + ->get('integromat_webhook_url'); + + Assert::notNull($url, 'Cannot push the post if there is no URL.'); + + $this->client->post($url, [ + 'form_params' => [ + 'text' => $this->t('@text', ['@text' => $post->toTweet()]) + ->render(), + ], + ]); + } + +}