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.
27 lines
593 B
PHP
27 lines
593 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Drupal\custom\Repository;
|
|
|
|
use Drupal\Core\Entity\EntityStorageInterface;
|
|
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
|
use Illuminate\Support\Collection;
|
|
|
|
final class PostRepository {
|
|
|
|
private EntityStorageInterface $nodeStorage;
|
|
|
|
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
|
|
$this->nodeStorage = $entityTypeManager->getStorage('node');
|
|
}
|
|
|
|
public function getAll(): Collection {
|
|
return new Collection(
|
|
$this->nodeStorage->loadByProperties([
|
|
'type' => 'post',
|
|
])
|
|
);
|
|
}
|
|
|
|
}
|