Skip to content

Commit

Permalink
Introduce trait ModalOpener
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Sep 6, 2023
1 parent 72bb31c commit 1bec467
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions src/Common/ModalOpener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace ipl\Web\Common;

use ipl\Html\BaseHtmlElement;
use ipl\Web\Url;
use ipl\Web\Widget\ActionLink;
use ipl\Web\Widget\ButtonLink;
use ipl\Web\Widget\Link;

trait ModalOpener
{
/**
* Add the modal opener attributes to the give element
*
* @param BaseHtmlElement $element
*
* @return BaseHtmlElement The provided element
*/
public static function addTo(BaseHtmlElement $element): BaseHtmlElement
{
$element
->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));
}
}

0 comments on commit 1bec467

Please sign in to comment.