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

Conversation

mariannuar
Copy link
Collaborator

@mariannuar mariannuar commented Dec 17, 2024

READY FOR REVIEW

Summary

Fix empty heading on postcards without title

Urgency

medium

Steps to Test

  1. Go to https://hs-traditional-hjupmoiykro8of7nlzyvwahjo999gbjf.tugboatqa.com/components/collections-0/collections-postcards/vertical-cards/vertical-cards-raised-cards
  2. Scroll down to Vertical Postcards with Title, Image and Link in a Collection and Vertical Postcards with Title and Image in a Collection (first of the third row of cards)
  3. Confirm that if there isn't a title in the card, there isn't an h2 in the markup
  4. Please test this in other cards (in views too) by editing the card and removing the card title

PR Checklist


@ahughes3 ahughes3 temporarily deployed to Tugboat December 17, 2024 19:40 Destroyed
@mariannuar mariannuar self-assigned this Dec 17, 2024
@mariannuar mariannuar requested a review from cienvaras December 17, 2024 20:48
Copy link
Collaborator

@cienvaras cienvaras left a comment

Choose a reason for hiding this comment

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

@mariannuar LGTM!

@ahughes3 Ready for you to review

@cienvaras cienvaras requested a review from ahughes3 December 19, 2024 19:41
@cienvaras cienvaras assigned ahughes3 and unassigned mariannuar Dec 19, 2024
@cienvaras
Copy link
Collaborator

@ahughes3 Please take a look at this comment before approving the PR. The Chemistry site is not in Tugboat, but the existing links in the cards break after applying this fix. I think that the fix is still necessary, but descriptive titles should be added if they want to keep the links working.

@ahughes3 ahughes3 temporarily deployed to Tugboat January 6, 2025 17:34 Destroyed
Base automatically changed from 11.6.1-release to develop January 8, 2025 16:39
@ahughes3 ahughes3 removed their assignment Jan 8, 2025
Copy link
Collaborator

@ahughes3 ahughes3 left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

Copy link
Collaborator

@sethprime sethprime left a comment

Choose a reason for hiding this comment

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

LGTM
Verified that vertical postcards without titles do not display an empty H2 tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants