Run on insert and update rather than pre-save

This commit is contained in:
Oliver Davies 2020-09-04 19:19:18 +01:00
parent 061b1177f5
commit 9219d10137

View file

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