diff options
| author | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2026-03-09 09:18:53 +0100 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2026-03-09 09:18:53 +0100 |
| commit | 08da9f257ff4efc98dd058e81984ac9bd6e46639 (patch) | |
| tree | 5e397bb3771fa096b30d435a12bc6ab8687751b2 /lib/classes/Icon.php | |
| parent | ef89c567131c55840192820ed7510497d970f36d (diff) | |
deprecate asSvg in favor of asImg, fixes #6330
Closes #6330
Merge request studip/studip!4802
Diffstat (limited to 'lib/classes/Icon.php')
| -rw-r--r-- | lib/classes/Icon.php | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/lib/classes/Icon.php b/lib/classes/Icon.php index 509664e..8306181 100644 --- a/lib/classes/Icon.php +++ b/lib/classes/Icon.php @@ -198,7 +198,7 @@ class Icon implements JsonSerializable */ public function __toString() { - return $this->asSvg(); + return $this->asImg(); } public function jsonSerialize(): mixed @@ -207,35 +207,49 @@ class Icon implements JsonSerializable } /** - * Renders the icon inside an img html tag. + * Renders the icon inside as an svg image. * * @param int $size Optional; Defines the dimension in px of the rendered icon; FALSE prevents any * width or height attributes * @param Array $view_attributes Optional; Additional attributes to pass * into the rendered output * @return String containing the html representation for the icon. + * + * @deprecated will be removed in Stud.IP 7.0. Use `asImg` instead. */ - public function asImg($size = null, $view_attributes = []) + public function asSvg($size = self::SIZE_DEFAULT, $view_attributes = []): string { - if (is_array($size)) { - [$view_attributes, $size] = [$size, null]; - } - return sprintf( - '<img %s>', - arrayToHtmlAttributes( - $this->prepareHTMLAttributes($size, $view_attributes) - ) - ); + return $this->asImg(...func_get_args()); } - public function asSvg($size = self::SIZE_DEFAULT, $view_attributes = []): string - { - if (self::isStatic($this->shape)) { - return $this->asImg($size, $view_attributes); + /** + * Renders the icon as an HTML image. + * + * @param int $size Optional; Defines the dimension in px of the rendered icon; FALSE prevents any + * width or height attributes + * @param Array $view_attributes Optional; Additional attributes to pass + * into the rendered output + * @param bool $force_img_tag Optional; If true, the icon will always be rendered as an img tag. + * @return String containing the html representation for the icon. + */ + public function asImg( + $size = self::SIZE_DEFAULT, + $view_attributes = [], + bool $force_img_tag = false + ): string { + if (is_array($size)) { + [$view_attributes, $size] = [$size, self::SIZE_DEFAULT]; } - if (is_array($size)) { - [$view_attributes, $size] = [$size, $size['size'] ?? self::SIZE_DEFAULT]; + $size ??= self::SIZE_DEFAULT; + + if ($force_img_tag || self::isStatic($this->shape)) { + return sprintf( + '<img %s>', + arrayToHtmlAttributes( + $this->prepareHTMLAttributes($size, $view_attributes) + ) + ); } $cacheKey = md5(json_encode([ @@ -305,7 +319,7 @@ class Icon implements JsonSerializable $text = isset($view_attributes['text']) ? htmlReady($view_attributes['text']) : ''; - $svgContent = $this->asSvg($size, $view_attributes); + $svgContent = $this->asImg($size, $view_attributes); if ($without_label) { return sprintf( |
