diff options
Diffstat (limited to 'lib/classes')
| -rw-r--r-- | lib/classes/Icon.php | 52 | ||||
| -rw-r--r-- | lib/classes/forms/Link.php | 2 | ||||
| -rw-r--r-- | lib/classes/globalsearch/GlobalSearchCourses.php | 6 | ||||
| -rw-r--r-- | lib/classes/globalsearch/GlobalSearchStudygroups.php | 6 | ||||
| -rw-r--r-- | lib/classes/sidebar/CourseManagementSelectWidget.php | 2 | ||||
| -rw-r--r-- | lib/classes/sidebar/LinkElement.php | 4 |
6 files changed, 43 insertions, 29 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( diff --git a/lib/classes/forms/Link.php b/lib/classes/forms/Link.php index eeb0244..6f26f28 100644 --- a/lib/classes/forms/Link.php +++ b/lib/classes/forms/Link.php @@ -159,7 +159,7 @@ class Link extends Part '<div class="formpart"><a href="%1$s" %2$s>%3$s %4$s</a></div>', \URLHelper::getLink($this->url, [], true), arrayToHtmlAttributes($this->attributes), - $this->icon ? $this->icon->asSvg(['class' => 'text-bottom']) : '', + $this->icon ? $this->icon->asImg(['class' => 'text-bottom']) : '', htmlReady($this->label) ); } diff --git a/lib/classes/globalsearch/GlobalSearchCourses.php b/lib/classes/globalsearch/GlobalSearchCourses.php index a02e691..939203c 100644 --- a/lib/classes/globalsearch/GlobalSearchCourses.php +++ b/lib/classes/globalsearch/GlobalSearchCourses.php @@ -185,21 +185,21 @@ class GlobalSearchCourses extends GlobalSearchModule implements GlobalSearchFull 'decline-circle', Icon::ROLE_STATUS_YELLOW, tooltip2(_('Eingeschränkter Zugang')) - )->asSvg(); + )->asImg(); break; case 2: $admission_state = Icon::create( 'decline-circle', Icon::ROLE_STATUS_RED, tooltip2(_('Kein Zugang')) - )->asSvg(); + )->asImg(); break; default: $admission_state = Icon::create( 'check-circle', Icon::ROLE_STATUS_GREEN, tooltip2(_('Uneingeschränkter Zugang')) - )->asSvg(); + )->asImg(); } } diff --git a/lib/classes/globalsearch/GlobalSearchStudygroups.php b/lib/classes/globalsearch/GlobalSearchStudygroups.php index 74bc11f..a9f1398 100644 --- a/lib/classes/globalsearch/GlobalSearchStudygroups.php +++ b/lib/classes/globalsearch/GlobalSearchStudygroups.php @@ -188,21 +188,21 @@ class GlobalSearchStudygroups extends GlobalSearchModule implements GlobalSearch 'decline-circle', Icon::ROLE_STATUS_YELLOW, tooltip2(_('Eingeschränkter Zugang')) - )->asSvg(); + )->asImg(); break; case 2: $admission_state = Icon::create( 'decline-circle', Icon::ROLE_STATUS_RED, tooltip2(_('Kein Zugang')) - )->asSvg(); + )->asImg(); break; default: $admission_state = Icon::create( 'check-circle', Icon::ROLE_STATUS_GREEN, tooltip2(_('Uneingeschränkter Zugang')) - )->asSvg(); + )->asImg(); } } diff --git a/lib/classes/sidebar/CourseManagementSelectWidget.php b/lib/classes/sidebar/CourseManagementSelectWidget.php index 8f10eaa..3ce9d80 100644 --- a/lib/classes/sidebar/CourseManagementSelectWidget.php +++ b/lib/classes/sidebar/CourseManagementSelectWidget.php @@ -19,7 +19,7 @@ class CourseManagementSelectWidget extends SelectWidget '<a href="%s" title="%s" data-dialog="size=auto">%s</a>', URLHelper::getURL('dispatch.php/course/management/order_settings', ['cid' => $this->course->id, 'from' => Request::url()]), _('Sortiereinstellungen'), - Icon::create('settings')->asSvg(['title' => _('Sortiereinstellungen')]) + Icon::create('settings')->asImg(['title' => _('Sortiereinstellungen')]) ); $this->setExtra($extra); $this->class = 'nested-select'; diff --git a/lib/classes/sidebar/LinkElement.php b/lib/classes/sidebar/LinkElement.php index 0376a47..9214f10 100644 --- a/lib/classes/sidebar/LinkElement.php +++ b/lib/classes/sidebar/LinkElement.php @@ -241,7 +241,7 @@ class LinkElement extends WidgetElement implements ArrayAccess '<%1$s %2$s>%3$s%4$s</%1$s>', $tag, arrayToHtmlAttributes($attributes), - $icon->asSvg(), + $icon->asImg(), htmlReady($this->label) ); } @@ -257,7 +257,7 @@ class LinkElement extends WidgetElement implements ArrayAccess '<button formaction="%s" %s>%s %s</button>', htmlReady($this->url), arrayToHtmlAttributes((array) $this->attributes), - $icon?->asSvg() ?? '', + $icon?->asImg() ?? '', htmlReady($this->label) ); } |
