Push to IFTTT

References #328
This commit is contained in:
Oliver Davies 2021-01-10 18:01:20 +00:00
parent 790b221646
commit 383c0d0fdf

View file

@ -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();