setContent($content) ->setUrl($url) ->getAttributes() ->add($attributes) ->registerAttributeCallback('href', [$this, 'createHrefAttribute']); } /** * Get the URL of the link * * @return Url */ public function getUrl() { return $this->url; } /** * Set the URL of the link * * @param Url|string $url * * @return $this */ public function setUrl($url) { if (! $url instanceof Url) { try { $url = Url::fromPath($url); } catch (\Exception $e) { $url = 'invalid'; } } $this->url = $url; return $this; } /** * Create and return the href attribute * * Used as attribute callback for the href attribute. * * @return Attribute */ public function createHrefAttribute() { return new Attribute('href', (string) $this->getUrl()); } /** * Open this link in a modal * * @return $this */ public function openInModal(): self { $this->getAttributes() ->set('data-icinga-modal', true) ->set('data-no-icinga-ajax', true); return $this; } }