Refactor sending posts to social media
This commit is contained in:
parent
59a98b8d78
commit
92f1c0f84c
|
@ -1,5 +1,6 @@
|
||||||
services:
|
services:
|
||||||
Drupal\opdavies_blog\EventSubscriber\PushBlogPostToSocialMedia:
|
Drupal\opdavies_blog\EventSubscriber\PushBlogPostToSocialMedia:
|
||||||
|
autowire: true
|
||||||
tags:
|
tags:
|
||||||
- { name: event_subscriber }
|
- { name: event_subscriber }
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,29 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Drupal\opdavies_blog\EventSubscriber;
|
namespace Drupal\opdavies_blog\EventSubscriber;
|
||||||
|
|
||||||
|
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||||
|
use Drupal\Core\Config\ImmutableConfig;
|
||||||
use Drupal\hook_event_dispatcher\Event\Entity\BaseEntityEvent;
|
use Drupal\hook_event_dispatcher\Event\Entity\BaseEntityEvent;
|
||||||
use Drupal\hook_event_dispatcher\HookEventDispatcherInterface;
|
use Drupal\hook_event_dispatcher\HookEventDispatcherInterface;
|
||||||
use Drupal\opdavies_blog\Entity\Node\Post;
|
use Drupal\opdavies_blog\Entity\Node\Post;
|
||||||
|
use GuzzleHttp\Client;
|
||||||
|
use GuzzleHttp\ClientInterface;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
|
||||||
final class PushBlogPostToSocialMedia implements EventSubscriberInterface {
|
final class PushBlogPostToSocialMedia implements EventSubscriberInterface {
|
||||||
|
|
||||||
|
private ClientInterface $client;
|
||||||
|
|
||||||
|
private ImmutableConfig $config;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
ConfigFactoryInterface $configFactory,
|
||||||
|
Client $client
|
||||||
|
) {
|
||||||
|
$this->client = $client;
|
||||||
|
$this->config = $configFactory->get('opdavies_talks.config');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
|
@ -45,14 +61,11 @@ final class PushBlogPostToSocialMedia implements EventSubscriberInterface {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$url = \Drupal::configFactory()->get('opdavies_talks.config')
|
if (!$url = $this->config->get('zapier_post_tweet_url')) {
|
||||||
->get('zapier_post_tweet_url');
|
|
||||||
|
|
||||||
if (!$url) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
\Drupal::httpClient()->post($url, [
|
$this->client->post($url, [
|
||||||
'form_params' => [
|
'form_params' => [
|
||||||
'message' => $entity->toTweet(),
|
'message' => $entity->toTweet(),
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue