diff --git a/src/Plugin/QueueWorker/MessageSubscribe.php b/src/Plugin/QueueWorker/MessageSubscribe.php index fd83c1d..20708a4 100644 --- a/src/Plugin/QueueWorker/MessageSubscribe.php +++ b/src/Plugin/QueueWorker/MessageSubscribe.php @@ -2,6 +2,7 @@ namespace Drupal\message_subscribe\Plugin\QueueWorker; +use Drupal\Core\Entity\EntityPublishedInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Queue\QueueWorkerBase; use Drupal\message_subscribe\SubscribersInterface; @@ -60,10 +61,16 @@ public function processItem($data) { // Reload message and entity. $message = $message->load($message->id()); $entity = $entity->load($entity->id()); + if (!$entity || !$message) { return; } + if ($entity instanceof EntityPublishedInterface && !$entity->isPublished()) { + // Entity is no longer published. + return; + } + // Denotes this is being processed from a queue worker. $subscribe_options['queue'] = TRUE; $this->subscribers->sendMessage($entity, $message, $notify_options, $subscribe_options, $context);