From 909374edcb0441e5feef57e5d97d61e401de006a Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 21 Apr 2021 00:44:56 +0100 Subject: [PATCH] Remove references to the toTweet() method --- .../blog/src/Service/PostPusher/IftttPostPusher.php | 7 +++++-- .../blog/src/Service/PostPusher/IntegromatPostPusher.php | 7 +++++-- .../blog/src/Service/PostPusher/WebhookPostPusher.php | 9 ++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/web/modules/custom/blog/src/Service/PostPusher/IftttPostPusher.php b/web/modules/custom/blog/src/Service/PostPusher/IftttPostPusher.php index db9b36b..e997903 100644 --- a/web/modules/custom/blog/src/Service/PostPusher/IftttPostPusher.php +++ b/web/modules/custom/blog/src/Service/PostPusher/IftttPostPusher.php @@ -6,6 +6,7 @@ namespace Drupal\opdavies_blog\Service\PostPusher; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\opdavies_blog\Action\ConvertPostToTweet; use Drupal\opdavies_blog\Entity\Node\Post; use GuzzleHttp\ClientInterface; use Webmozart\Assert\Assert; @@ -17,12 +18,14 @@ final class IftttPostPusher extends WebhookPostPusher { private ConfigFactoryInterface $configFactory; public function __construct( + ConvertPostToTweet $convertPostToTweetAction, ClientInterface $client, ConfigFactoryInterface $configFactory ) { + $this->convertPostToTweetAction = $convertPostToTweetAction; $this->configFactory = $configFactory; - parent::__construct($client); + parent::__construct($convertPostToTweetAction, $client); } public function push(Post $post): void { @@ -34,7 +37,7 @@ final class IftttPostPusher extends WebhookPostPusher { $this->client->post($url, [ 'form_params' => [ - 'value1' => $this->t('Blogged: @text', ['@text' => $post->toTweet()]) + 'value1' => $this->t('Blogged: @text', ['@text' => ($this->convertPostToTweetAction)($post)]) ->render(), ], ]); diff --git a/web/modules/custom/blog/src/Service/PostPusher/IntegromatPostPusher.php b/web/modules/custom/blog/src/Service/PostPusher/IntegromatPostPusher.php index 2b2367b..ed2c593 100644 --- a/web/modules/custom/blog/src/Service/PostPusher/IntegromatPostPusher.php +++ b/web/modules/custom/blog/src/Service/PostPusher/IntegromatPostPusher.php @@ -6,6 +6,7 @@ namespace Drupal\opdavies_blog\Service\PostPusher; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\opdavies_blog\Action\ConvertPostToTweet; use Drupal\opdavies_blog\Entity\Node\Post; use GuzzleHttp\ClientInterface; use Webmozart\Assert\Assert; @@ -17,12 +18,14 @@ final class IntegromatPostPusher extends WebhookPostPusher { private ConfigFactoryInterface $configFactory; public function __construct( + ConvertPostToTweet $convertPostToTweetAction, ClientInterface $client, ConfigFactoryInterface $configFactory ) { + $this->convertPostToTweetAction = $convertPostToTweetAction; $this->configFactory = $configFactory; - parent::__construct($client); + parent::__construct($convertPostToTweetAction, $client); } public function push(Post $post): void { @@ -34,7 +37,7 @@ final class IntegromatPostPusher extends WebhookPostPusher { $this->client->post($url, [ 'form_params' => [ - 'text' => $this->t('@text', ['@text' => $post->toTweet()]) + 'text' => $this->t('@text', ['@text' => ($this->convertPostToTweetAction)($post)]) ->render(), ], ]); diff --git a/web/modules/custom/blog/src/Service/PostPusher/WebhookPostPusher.php b/web/modules/custom/blog/src/Service/PostPusher/WebhookPostPusher.php index 62af191..e9fd8f5 100644 --- a/web/modules/custom/blog/src/Service/PostPusher/WebhookPostPusher.php +++ b/web/modules/custom/blog/src/Service/PostPusher/WebhookPostPusher.php @@ -4,13 +4,20 @@ declare(strict_types=1); namespace Drupal\opdavies_blog\Service\PostPusher; +use Drupal\opdavies_blog\Action\ConvertPostToTweet; use GuzzleHttp\ClientInterface; abstract class WebhookPostPusher implements PostPusher { + protected ConvertPostToTweet $convertPostToTweetAction; + protected ClientInterface $client; - public function __construct(ClientInterface $client) { + public function __construct( + ConvertPostToTweet $convertPostToTweetAction, + ClientInterface $client + ) { + $this->convertPostToTweetAction = $convertPostToTweetAction; $this->client = $client; }