diff options
| author | Ron Lucke <lucke@elan-ev.de> | 2025-07-14 09:36:18 +0200 |
|---|---|---|
| committer | Ron Lucke <lucke@elan-ev.de> | 2025-07-14 09:36:18 +0200 |
| commit | 4355ded9bc56e0b06fbceffe61ddc37061cc3bc7 (patch) | |
| tree | 348493b6b0fd1286b86f213e5077413b97cf9747 /lib/classes/sidebar/LinkElement.php | |
| parent | 1e59dd2dacc51b3313d7780b66d4bf72e0484f86 (diff) | |
Color-Themes-System, fixes #5361
Closes #5361
Merge request studip/studip!4038
Diffstat (limited to 'lib/classes/sidebar/LinkElement.php')
| -rw-r--r-- | lib/classes/sidebar/LinkElement.php | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/lib/classes/sidebar/LinkElement.php b/lib/classes/sidebar/LinkElement.php index f8d768b..0376a47 100644 --- a/lib/classes/sidebar/LinkElement.php +++ b/lib/classes/sidebar/LinkElement.php @@ -216,17 +216,48 @@ class LinkElement extends WidgetElement implements ArrayAccess ); } + public function renderWithIcon($icon) + { + $disabled = $this->isDisabled(); + + if ($this->as_button && !$disabled) { + return $this->renderButton($icon); + } + + if ($this->active) { + $this->addClass('active'); + } + + $attributes = (array) $this->attributes; + + if ($disabled) { + $tag = 'span'; + } else { + $tag = 'a'; + $attributes['href'] = $this->url; + } + + return sprintf( + '<%1$s %2$s>%3$s%4$s</%1$s>', + $tag, + arrayToHtmlAttributes($attributes), + $icon->asSvg(), + htmlReady($this->label) + ); + } + /** * Renders the element as a button/form. * * @return string */ - protected function renderButton() + protected function renderButton(?Icon $icon = null) { return sprintf( - '<button formaction="%s" %s>%s</button>', + '<button formaction="%s" %s>%s %s</button>', htmlReady($this->url), arrayToHtmlAttributes((array) $this->attributes), + $icon?->asSvg() ?? '', htmlReady($this->label) ); } |
