From b11a32a60aa19df85a7c107f4e110f0ec37b9685 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Fri, 8 Sep 2023 09:32:32 +0200 Subject: [PATCH] Link: Introduce `Link::openInModal()` method --- src/Common/ModalOpener.php | 77 -------------------------------------- src/Widget/Link.php | 18 +++++++++ 2 files changed, 18 insertions(+), 77 deletions(-) delete mode 100644 src/Common/ModalOpener.php diff --git a/src/Common/ModalOpener.php b/src/Common/ModalOpener.php deleted file mode 100644 index dba3b26d..00000000 --- a/src/Common/ModalOpener.php +++ /dev/null @@ -1,77 +0,0 @@ -getAttributes() - ->set([ - 'data-icinga-modal' => true, - 'data-no-icinga-ajax' => true - ]); - - return $element; - } - - /** - * Create an HTML link - * - * Create an HTML link that opens a modal once clicked - * - * @param string|Url $url - * @param mixed $content - * - * @return BaseHtmlElement - */ - public static function createLink($url, $content): BaseHtmlElement - { - return static::addTo(new Link($content, $url)); - } - - /** - * Create a button link - * - * Create a button link that opens a modal once clicked - * - * @param string|Url $url - * @param mixed $content - * @param string|null $icon - * - * @return BaseHtmlElement - */ - public static function createButtonLink($url, $content, string $icon = null): BaseHtmlElement - { - return static::addTo(new ButtonLink($content, $url, $icon)); - } - - /** - * Create an action link - * - * Create an action link that opens a modal once clicked - * - * @param string|Url $url - * @param mixed $content - * @param string|null $icon - * @return BaseHtmlElement - */ - public static function createActionLink($url, $content, string $icon = null): BaseHtmlElement - { - return static::addTo(new ActionLink($content, $url, $icon)); - } -} diff --git a/src/Widget/Link.php b/src/Widget/Link.php index 2d7c9f57..ebd0d8af 100644 --- a/src/Widget/Link.php +++ b/src/Widget/Link.php @@ -80,4 +80,22 @@ 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( + Attributes::create([ + 'data-icinga-modal' => true, + 'data-no-icinga-ajax' => true + ]) + ); + + return $this; + } }