From 9219d101379c8d155d77dd345990c9145fa0e376 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 4 Sep 2020 19:19:18 +0100 Subject: [PATCH] Run on insert and update rather than pre-save --- .../src/EventSubscriber/PushBlogPostToSocialMedia.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/web/modules/custom/opdavies_blog/src/EventSubscriber/PushBlogPostToSocialMedia.php b/web/modules/custom/opdavies_blog/src/EventSubscriber/PushBlogPostToSocialMedia.php index 5418a27..3643873 100644 --- a/web/modules/custom/opdavies_blog/src/EventSubscriber/PushBlogPostToSocialMedia.php +++ b/web/modules/custom/opdavies_blog/src/EventSubscriber/PushBlogPostToSocialMedia.php @@ -32,11 +32,12 @@ final class PushBlogPostToSocialMedia implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - HookEventDispatcherInterface::ENTITY_PRE_SAVE => 'onEntityPreSave', + HookEventDispatcherInterface::ENTITY_INSERT => 'onEntityUpdate', + HookEventDispatcherInterface::ENTITY_UPDATE => 'onEntityUpdate', ]; } - public function onEntityPresave(BaseEntityEvent $event): void { + public function onEntityUpdate(BaseEntityEvent $event): void { $entity = $event->getEntity(); if ($entity->getEntityTypeId() != 'node') { @@ -72,6 +73,7 @@ final class PushBlogPostToSocialMedia implements EventSubscriberInterface { ]); $entity->set('field_sent_to_social_media', TRUE); + $entity->save(); } }