From 9f077caceb71c1012ee42119ed64fb4c68bb6ce3 Mon Sep 17 00:00:00 2001 From: Aaron Bidzan Date: Fri, 20 Mar 2026 16:40:21 +0100 Subject: [PATCH] 46747: Implements withOpenInNewViewport as an option for images --- .../ILIAS/UI/src/Component/Image/Image.php | 10 ++++++++++ .../Implementation/Component/Image/Image.php | 19 +++++++++++++++++++ .../Component/Image/Renderer.php | 6 ++++++ .../Image/Standard/with_string_action.php | 3 ++- .../templates/default/Image/tpl.image.html | 4 ++-- 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/components/ILIAS/UI/src/Component/Image/Image.php b/components/ILIAS/UI/src/Component/Image/Image.php index e2552441593a..3438232920c7 100755 --- a/components/ILIAS/UI/src/Component/Image/Image.php +++ b/components/ILIAS/UI/src/Component/Image/Image.php @@ -99,4 +99,14 @@ public function withAction($action): Image; * @return string|Signal[] */ public function getAction(); + + /** + * Set if the image action should be opened in a new viewport. + */ + public function withOpenInNewViewport(bool $open_in_new_viewport): Image; + + /** + * Get if the image action should be opened in a new viewport. + */ + public function getOpenInNewViewport(): bool; } diff --git a/components/ILIAS/UI/src/Implementation/Component/Image/Image.php b/components/ILIAS/UI/src/Implementation/Component/Image/Image.php index 77758a9b93e6..04cf9f44c946 100755 --- a/components/ILIAS/UI/src/Implementation/Component/Image/Image.php +++ b/components/ILIAS/UI/src/Implementation/Component/Image/Image.php @@ -46,6 +46,7 @@ class Image implements C\Image\Image private array $additional_high_res_sources = []; private string $alt; protected ?string $action = ''; + protected bool $open_in_new_viewport = false; public function __construct(string $type, string $source, string $alt) { @@ -165,4 +166,22 @@ public function appendOnClick(Signal $signal): C\Clickable { return $this->appendTriggeredSignal($signal, 'click'); } + + /** + * @inheritdoc + */ + public function withOpenInNewViewport(bool $open_in_new_viewport): C\Image\Image + { + $clone = clone $this; + $clone->open_in_new_viewport = $open_in_new_viewport; + return $clone; + } + + /** + * @inheritdoc + */ + public function getOpenInNewViewport(): bool + { + return $this->open_in_new_viewport; + } } diff --git a/components/ILIAS/UI/src/Implementation/Component/Image/Renderer.php b/components/ILIAS/UI/src/Implementation/Component/Image/Renderer.php index 11b7f119c0ba..9838effcbf0e 100755 --- a/components/ILIAS/UI/src/Implementation/Component/Image/Renderer.php +++ b/components/ILIAS/UI/src/Implementation/Component/Image/Renderer.php @@ -68,6 +68,12 @@ public function render(Component\Component $component, RendererInterface $defaul $tpl->setCurrentBlock("with_href"); $tpl->setVariable("HREF", $component->getAction()); $tpl->parseCurrentBlock(); + + if ($component->getOpenInNewViewport()) { + $tpl->setCurrentBlock("with_target"); + $tpl->setVariable("TARGET", "_blank"); + $tpl->parseCurrentBlock(); + } } if (is_array($component->getAction())) { diff --git a/components/ILIAS/UI/src/examples/Image/Standard/with_string_action.php b/components/ILIAS/UI/src/examples/Image/Standard/with_string_action.php index 547f5c099c4d..7cef36b76f5f 100755 --- a/components/ILIAS/UI/src/examples/Image/Standard/with_string_action.php +++ b/components/ILIAS/UI/src/examples/Image/Standard/with_string_action.php @@ -40,7 +40,8 @@ function with_string_action() $image = $f->image()->standard( "assets/ui-examples/images/Image/HeaderIconLarge.svg", "Thumbnail Example" - )->withAction("https://www.ilias.de"); + )->withAction("https://www.ilias.de") + ->withOpenInNewViewport(true); $html = $renderer->render($image); diff --git a/components/ILIAS/UI/src/templates/default/Image/tpl.image.html b/components/ILIAS/UI/src/templates/default/Image/tpl.image.html index eb57826b0c5c..59c0452fd381 100755 --- a/components/ILIAS/UI/src/templates/default/Image/tpl.image.html +++ b/components/ILIAS/UI/src/templates/default/Image/tpl.image.html @@ -1,5 +1,5 @@ - href="{HREF}" id="{ID}"> + href="{HREF}" id="{ID}" target="{TARGET}" rel="noopener"> @@ -12,4 +12,4 @@ - \ No newline at end of file +