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-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-08-14 14:01:23 +01:00
|
|
|
public function getExternalLink(): ?array {
|
|
|
|
return ($link = $this->get('field_external_link')->get(0))
|
|
|
|
? $link->getValue()
|
|
|
|
: NULL;
|
|
|
|
}
|
|
|
|
|
2020-08-12 20:28:19 +01:00
|
|
|
public function hasBeenSentToSocialMedia(): bool {
|
|
|
|
return (bool) $this->get('field_sent_to_social_media')->getString();
|
|
|
|
}
|
|
|
|
|
2020-05-29 21:35:21 +01:00
|
|
|
public function hasTweet(): bool {
|
|
|
|
return (bool) $this->get('field_has_tweet')->getString();
|
|
|
|
}
|
|
|
|
|
2020-08-14 14:01:23 +01:00
|
|
|
public function isExternalPost(): bool {
|
|
|
|
return (bool) $this->getExternalLink();
|
|
|
|
}
|
|
|
|
|
2020-07-19 20:12:08 +01:00
|
|
|
public function toTweet(): string {
|
|
|
|
// TODO: Add tags.
|
|
|
|
|
|
|
|
$parts = [$this->label(), $this->url('canonical', ['absolute' => TRUE])];
|
|
|
|
|
|
|
|
return implode(PHP_EOL . PHP_EOL, $parts);
|
|
|
|
}
|
|
|
|
|
2020-05-29 21:35:21 +01:00
|
|
|
}
|