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 3 commits into
base: 11.6.4-release
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
Contributor

@joegl joegl Jan 31, 2025

Choose a reason for hiding this comment

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

I'm also trying to understand what's going on here. If $variables['title'] is equal to an empty string it shouldn't get past the empty() conditional on line 186. Unless the renderInIsolation() method is returning an empty string?

Additionally, on line 188 if $title is empty, what's the purpose of stripping tags and trimming an empty string?

@ahughes3 ahughes3 temporarily deployed to Tugboat January 13, 2025 19:35 Destroyed
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.

…-5988--fix-empty-heading-on-postcards-without-title
@cienvaras cienvaras changed the base branch from develop to 11.6.3-release January 21, 2025 00:28
@ahughes3 ahughes3 assigned joegl and unassigned pookmish Jan 21, 2025
Base automatically changed from 11.6.3-release to develop January 22, 2025 16:25
@cienvaras
Copy link
Collaborator

@ahughes3 I noticed that this ticket was closed. While the reported issue was a content problem, there's still an issue in the platform that will output an empty link and heading in the cards if the URL is present and the title field is empty. This PR prevents the empty elements from being displayed, but there's still an usability issue, because the users can add an URL in the cards that just just won't work if the title is absent, which can be confusing. I'd recommend to create a follow up ticket for fixing that.

As for this PR, we can merge it to have a partial fix and prevent more SiteImprove errors or close it and work in a more complete fix in the follow up ticket. What do you think?

@joegl
Copy link
Contributor

joegl commented Jan 27, 2025

Holding off on review until @ahughes3 responds to @cienvaras

@ahughes3 ahughes3 requested a review from joegl January 29, 2025 18:23
@ahughes3
Copy link
Collaborator

@cienvaras Let's move forward with this fix and create the follow up if this PR get's us in a better place that we are today

@joegl joegl changed the base branch from develop to 11.6.4-release January 29, 2025 19:24
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.

6 participants