Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions components/ILIAS/UI/src/Component/Image/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
19 changes: 19 additions & 0 deletions components/ILIAS/UI/src/Implementation/Component/Image/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- BEGIN action_begin -->
<a<!-- BEGIN with_href --> href="{HREF}"<!-- END with_href --><!-- BEGIN with_id --> id="{ID}"<!-- END with_id -->>
<a<!-- BEGIN with_href --> href="{HREF}"<!-- END with_href --><!-- BEGIN with_id --> id="{ID}"<!-- END with_id --><!-- BEGIN with_target --> target="{TARGET}" rel="noopener"<!-- END with_target -->>
<!-- END action_begin -->

<!-- BEGIN standard -->
Expand All @@ -12,4 +12,4 @@

<!-- BEGIN action_end -->
</a>
<!-- END action_end -->
<!-- END action_end -->
Loading