2020-05-29 21:35:21 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-08-24 09:26:44 +01:00
|
|
|
namespace Drupal\opdavies_blog\Entity\Node;
|
2020-05-29 21:35:21 +01:00
|
|
|
|
|
|
|
use Drupal\discoverable_entity_bundle_classes\ContentEntityBundleInterface;
|
2020-06-26 19:43:58 +01:00
|
|
|
use Drupal\node\Entity\Node;
|
2020-08-28 11:35:54 +01:00
|
|
|
use Drupal\taxonomy\Entity\Term;
|
2021-04-23 08:58:14 +01:00
|
|
|
use Illuminate\Support\Collection;
|
2020-05-29 21:35:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines an blog post node class.
|
|
|
|
*
|
|
|
|
* @ContentEntityBundleClass(
|
|
|
|
* label = @Translation("Blog post"),
|
|
|
|
* entity_type = "node",
|
|
|
|
* bundle = "post"
|
|
|
|
* );
|
|
|
|
*/
|
|
|
|
class Post extends Node implements ContentEntityBundleInterface {
|
|
|
|
|
2020-11-10 19:34:15 +00:00
|
|
|
public const FIELD_EXTERNAL_LINK = 'field_external_link';
|
|
|
|
public const FIELD_HAS_TWEET = 'field_has_tweet';
|
|
|
|
public const FIELD_SEND_TO_SOCIAL_MEDIA = 'field_send_to_social_media';
|
|
|
|
public const FIELD_SENT_TO_SOCIAL_MEDIA = 'field_sent_to_social_media';
|
|
|
|
public const FIELD_TAGS = 'field_tags';
|
|
|
|
|
2020-08-14 14:01:23 +01:00
|
|
|
public function getExternalLink(): ?array {
|
2020-11-10 19:34:15 +00:00
|
|
|
return ($link = $this->get(self::FIELD_EXTERNAL_LINK)->get(0))
|
2020-08-14 14:01:23 +01:00
|
|
|
? $link->getValue()
|
|
|
|
: NULL;
|
|
|
|
}
|
|
|
|
|
2020-08-28 11:35:54 +01:00
|
|
|
/**
|
|
|
|
* @return Collection|Term[]
|
|
|
|
*/
|
|
|
|
public function getTags(): Collection {
|
2020-11-10 19:34:15 +00:00
|
|
|
return new Collection($this->get(self::FIELD_TAGS)->referencedEntities());
|
2020-08-28 11:35:54 +01:00
|
|
|
}
|
|
|
|
|
2020-08-12 20:28:19 +01:00
|
|
|
public function hasBeenSentToSocialMedia(): bool {
|
2020-11-10 19:34:15 +00:00
|
|
|
return (bool) $this->get(self::FIELD_SENT_TO_SOCIAL_MEDIA)->getString();
|
2020-08-12 20:28:19 +01:00
|
|
|
}
|
|
|
|
|
2020-05-29 21:35:21 +01:00
|
|
|
public function hasTweet(): bool {
|
2020-11-10 19:34:15 +00:00
|
|
|
return (bool) $this->get(self::FIELD_HAS_TWEET)->getString();
|
2020-05-29 21:35:21 +01:00
|
|
|
}
|
|
|
|
|
2020-08-14 14:01:23 +01:00
|
|
|
public function isExternalPost(): bool {
|
|
|
|
return (bool) $this->getExternalLink();
|
|
|
|
}
|
|
|
|
|
2020-11-10 19:51:53 +00:00
|
|
|
public function markAsSentToSocialMedia(): self {
|
|
|
|
$this->set(self::FIELD_SENT_TO_SOCIAL_MEDIA, TRUE);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2020-08-28 11:35:54 +01:00
|
|
|
public function setTags(array $tags): void {
|
2020-11-10 19:34:15 +00:00
|
|
|
$this->set(self::FIELD_TAGS, $tags);
|
2020-08-28 11:35:54 +01:00
|
|
|
}
|
|
|
|
|
2020-10-07 22:54:56 +01:00
|
|
|
public function shouldSendToSocialMedia(): bool {
|
2020-11-10 19:34:15 +00:00
|
|
|
return (bool) $this->get(self::FIELD_SEND_TO_SOCIAL_MEDIA)->getString();
|
2020-10-07 22:54:56 +01:00
|
|
|
}
|
|
|
|
|
2020-07-19 20:12:08 +01:00
|
|
|
public function toTweet(): string {
|
2021-04-21 00:19:02 +01:00
|
|
|
return '';
|
2020-09-04 12:04:55 +01:00
|
|
|
}
|
|
|
|
|
2020-05-29 21:35:21 +01:00
|
|
|
}
|