-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |