Rename event subscriber classes
This commit is contained in:
parent
17179fbfe4
commit
7e06943be1
3 changed files with 4 additions and 4 deletions
|
@ -1,51 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opdavies_blog\EventSubscriber;
|
||||
|
||||
use Drupal\Core\Queue\QueueFactory;
|
||||
use Drupal\core_event_dispatcher\Event\Entity\AbstractEntityEvent;
|
||||
use Drupal\hook_event_dispatcher\HookEventDispatcherInterface;
|
||||
use Drupal\opdavies_blog\Entity\Node\Post;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
final class PushBlogPostToSocialMedia implements EventSubscriberInterface {
|
||||
|
||||
private QueueFactory $queueFactory;
|
||||
|
||||
public function __construct(QueueFactory $queueFactory) {
|
||||
$this->queueFactory = $queueFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function getSubscribedEvents() {
|
||||
return [
|
||||
HookEventDispatcherInterface::ENTITY_INSERT => 'onEntityUpdate',
|
||||
HookEventDispatcherInterface::ENTITY_UPDATE => 'onEntityUpdate',
|
||||
];
|
||||
}
|
||||
|
||||
public function onEntityUpdate(AbstractEntityEvent $event): void {
|
||||
$entity = $event->getEntity();
|
||||
|
||||
if ($entity->getEntityTypeId() != 'node') {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var Post $entity */
|
||||
if ($entity->bundle() != 'post') {
|
||||
return;
|
||||
}
|
||||
|
||||
$queue = $this->queueFactory->get('opdavies_blog_push_post_to_social_media');
|
||||
$queue->createQueue();
|
||||
|
||||
$queue->createItem([
|
||||
'post' => $entity,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue