Check if a post has previously been sent to social media, by checking the value of a `field_sent_to_social_media` field. This field is hidden on the node add/edit forms, and populated when a post is sent to social media. Once this happens, it will not be sent to social media again. This change also populates the field for all existing posts, so that they won't be re-sent to social media either.
17 lines
348 B
Text
17 lines
348 B
Text
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Drupal\custom\Repository\PostRepository;
|
|
|
|
/**
|
|
* Mark existing blog posts as sent to social media.
|
|
*/
|
|
function custom_update_8001(): void {
|
|
$posts = \Drupal::service(PostRepository::class)->getAll();
|
|
|
|
foreach ($posts as $post) {
|
|
$post->set('field_sent_to_social_media', TRUE);
|
|
$post->save();
|
|
}
|
|
}
|