]> BookStack Code Mirror - bookstack/blob - app/Activity/Notifications/MessageParts/EntityLinkMessageLine.php
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / app / Activity / Notifications / MessageParts / EntityLinkMessageLine.php
1 <?php
2
3 namespace BookStack\Activity\Notifications\MessageParts;
4
5 use BookStack\Entities\Models\Entity;
6 use Illuminate\Contracts\Support\Htmlable;
7 use Stringable;
8
9 /**
10  * A link to a specific entity in the system, with the text showing its name.
11  */
12 class EntityLinkMessageLine implements Htmlable, Stringable
13 {
14     public function __construct(
15         protected Entity $entity,
16         protected int $nameLength = 120,
17     ) {
18     }
19
20     public function toHtml(): string
21     {
22         return '<a href="' . e($this->entity->getUrl()) . '">' . e($this->entity->getShortName($this->nameLength)) . '</a>';
23     }
24
25     public function __toString(): string
26     {
27         return "{$this->entity->getShortName($this->nameLength)} ({$this->entity->getUrl()})";
28     }
29 }