Skip to content

Commit

Permalink
Add missing shy button prerender in title (ILIAS-eLearning#7571)
Browse files Browse the repository at this point in the history
(cherry picked from commit 78a24af)
(cherry picked from commit 4a46dd8)
  • Loading branch information
iszmais authored and Amstutz committed Jun 4, 2024
1 parent 8b067eb commit 2d91cdf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\UI\Implementation\Component\Card;

use ILIAS\UI\Implementation\Render\AbstractComponentRenderer;
Expand All @@ -42,10 +42,11 @@ public function render(Component\Component $component, RendererInterface $defaul
$tpl = $this->getTemplate("tpl.card.html", true, true);

$title = $component->getTitle();
$image_alt = $title;

if ($title instanceof Button || $title instanceof Link) {
if ($title instanceof Shy) {
$image_alt = $title->getLabel();
$title = $default_renderer->render($title);
} else {
$image_alt = $title;
}

if ($component->isHighlighted()) {
Expand Down
19 changes: 19 additions & 0 deletions components/ILIAS/UI/tests/Component/Card/CardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,23 @@ public function testRenderContentWithHighlight(): void

$this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
}

public function test_render_content_with_component_title(): void
{
$r = $this->getDefaultRenderer();
$c = $this->getBaseCard();
$title = new I\Component\Button\Shy('Card Title', '');
$c = $c->withTitle($title);

$html = $this->brutallyTrimHTML($r->render($c));

$expected_html =
"<div class=\"il-card thumbnail\">" .
" <div class=\"il-card-image-container\"><img src=\"src\" class=\"img-standard\" alt=\"open Card Title\" /></div>" .
" <div class=\"card-no-highlight\"></div>" .
" <div class=\"caption card-title\">" . $r->render($title) . "</div>" .
"</div>";

$this->assertHTMLEquals($this->brutallyTrimHTML($expected_html), $html);
}
}

0 comments on commit 2d91cdf

Please sign in to comment.