Automatically re-order tags on save

Fixes #167
This commit is contained in:
Oliver Davies 2020-08-28 11:35:54 +01:00
parent 5e107b48d6
commit 59a98b8d78
13 changed files with 268 additions and 0 deletions

View file

@ -6,6 +6,8 @@ namespace Drupal\opdavies_blog\Entity\Node;
use Drupal\discoverable_entity_bundle_classes\ContentEntityBundleInterface;
use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Term;
use Illuminate\Support\Collection;
/**
* Defines an blog post node class.
@ -24,6 +26,13 @@ class Post extends Node implements ContentEntityBundleInterface {
: NULL;
}
/**
* @return Collection|Term[]
*/
public function getTags(): Collection {
return new Collection($this->get('field_tags')->referencedEntities());
}
public function hasBeenSentToSocialMedia(): bool {
return (bool) $this->get('field_sent_to_social_media')->getString();
}
@ -36,6 +45,10 @@ class Post extends Node implements ContentEntityBundleInterface {
return (bool) $this->getExternalLink();
}
public function setTags(array $tags): void {
$this->set('field_tags', $tags);
}
public function toTweet(): string {
// TODO: Add tags.