Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

Commit

Permalink
Add post pushers as parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
opdavies committed Feb 25, 2021
1 parent 9a46b63 commit 24efdc8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
3 changes: 3 additions & 0 deletions web/modules/custom/blog/opdavies_blog.services.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
parameters:
container.autowiring.strict_mode: true
opdavies_blog.post_pushers:
- '@Drupal\opdavies_blog\Service\PostPusher\IftttPostPusher'
- '@Drupal\opdavies_blog\Service\PostPusher\IntegromatPostPusher'

services:
Drupal\Core\Config\ConfigFactoryInterface:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

namespace Drupal\opdavies_blog\Plugin\QueueWorker;

use Assert\Assertion;
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\IntegromatPostPusher;
use Drupal\opdavies_blog\Service\PostPusher\PostPusher;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -48,15 +47,22 @@ public static function create(
$pluginId,
$pluginDefinition
) {
$postPushers = [];

foreach ($container->getParameter('opdavies_blog.post_pushers') as $postPusher) {
Assertion::isInstanceOf($postPusher, '\stdClass');
Assertion::eq($postPusher->type, 'service');
Assertion::notEmpty($postPusher->id);

$postPushers[] = $container->get($postPusher->id);
}

return new static(
$configuration,
$pluginId,
$pluginDefinition,
$container->get('entity_type.manager')->getStorage('node'),
[
$container->get(IftttPostPusher::class),
$container->get(IntegromatPostPusher::class),
]
$postPushers
);
}

Expand Down

0 comments on commit 24efdc8

Please sign in to comment.