Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHS-5988: Fix empty heading on postcards without title #1699

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion docroot/modules/humsci/hs_layouts/hs_layouts.module
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,10 @@ function _hs_layouts_make_title_the_link(&$variables) {
$variables['href'] = $variables['href'] ?? htmlspecialchars_decode(trim(strip_tags($renderer->renderInIsolation($variables['button']))));
}
}

if (!empty($variables['title'])) {
$title = is_array($variables['title']) ? $renderer->renderInIsolation($variables['title']) : $variables['title'];
$variables['title'] = ['#markup' => trim(strip_tags($title))];
$variables['title'] = $title ?? ['#markup' => trim(strip_tags($title))];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this work? I'm not really understanding.

if $variables['title'] is a render array, we get the rendering, otherwise it's would be a string. But either way $title is not null/false, so it would always set the value to what is returned in line 187. The ?? .... doesn't really do anything at this point.

Copy link
Collaborator Author

@mariannuar mariannuar Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that in line 187 $title returned an empty string. So in line 188, if we don't add the ?? it will set $variables['title'] like this:

Screenshot 2025-01-09 at 8 42 55 AM

$variables['title'] will return an array in these scenario, so in the template vertical-card.html.twig it will seem that there's something in title even though it's an array with an #markup that is empty. This will add the h2.

}
}

Expand Down
Loading