parent
150c974040
commit
c5c774290d
2 changed files with 30 additions and 3 deletions
|
@ -50,11 +50,27 @@ class Post extends Node implements ContentEntityBundleInterface {
|
|||
}
|
||||
|
||||
public function toTweet(): string {
|
||||
// TODO: Add tags.
|
||||
|
||||
$parts = [$this->label(), $this->url('canonical', ['absolute' => TRUE])];
|
||||
$parts = [
|
||||
$this->label(),
|
||||
$this->url('canonical', ['absolute' => TRUE]),
|
||||
$this->convertTermsToHashtags(),
|
||||
];
|
||||
|
||||
return implode(PHP_EOL . PHP_EOL, $parts);
|
||||
}
|
||||
|
||||
private function convertTermsToHashtags(): string {
|
||||
return $this->getTags()
|
||||
->map(fn(Term $term) => $this->convertTermToHashtag($term))
|
||||
->implode(' ');
|
||||
}
|
||||
|
||||
private function convertTermToHashtag(Term $tag): string {
|
||||
$tagName = strtolower($tag->label());
|
||||
$tagName = "#{$tagName}";
|
||||
$tagName = str_replace(' ', '-', $tagName);
|
||||
|
||||
return $tagName;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue