'onEntityPreSave', ]; } public function onEntityPresave(BaseEntityEvent $event): void { $entity = $event->getEntity(); if ($entity->getEntityTypeId() != 'node') { return; } /** @var Post $entity */ if ($entity->bundle() != 'post') { return; } if (!$entity->isPublished()) { return; } // If this post has already been sent to social media, do not send it again. if ($entity->hasBeenSentToSocialMedia()) { return; } if ($entity->isExternalPost()) { return; } $url = \Drupal::configFactory()->get('opdavies_talks.config') ->get('zapier_post_tweet_url'); if (!$url) { return; } \Drupal::httpClient()->post($url, [ 'form_params' => [ 'message' => $entity->toTweet(), ], ]); $entity->set('field_sent_to_social_media', TRUE); } }