Extract helper methods
This commit is contained in:
parent
06c3da1880
commit
a656280e7b
5 changed files with 24 additions and 11 deletions
|
@ -7,7 +7,6 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Drupal\opdavies_blog\Entity\Post;
|
||||
use Drupal\opdavies_blog\Repository\PostRepository;
|
||||
|
||||
/**
|
||||
|
@ -17,7 +16,7 @@ function opdavies_blog_update_8001(): void {
|
|||
$posts = \Drupal::service(PostRepository::class)->getAll();
|
||||
|
||||
foreach ($posts as $post) {
|
||||
$post->set(Post::FIELD_SENT_TO_SOCIAL_MEDIA, TRUE);
|
||||
$post->markAsSentToSocialMedia();
|
||||
$post->save();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,12 @@ class Post extends Node implements ContentEntityBundleInterface {
|
|||
return (bool) $this->getExternalLink();
|
||||
}
|
||||
|
||||
public function markAsSentToSocialMedia(): self {
|
||||
$this->set(self::FIELD_SENT_TO_SOCIAL_MEDIA, TRUE);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setTags(array $tags): void {
|
||||
$this->set(self::FIELD_TAGS, $tags);
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ final class PushBlogPostToSocialMedia implements EventSubscriberInterface {
|
|||
],
|
||||
]);
|
||||
|
||||
$entity->set(Post::FIELD_SENT_TO_SOCIAL_MEDIA, TRUE);
|
||||
$entity->markAsSentToSocialMedia();
|
||||
$entity->save();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue