-
Notifications
You must be signed in to change notification settings - Fork 17
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
Update NewsImage to render multiple defaults #3096
Update NewsImage to render multiple defaults #3096
Conversation
The logic to render an image for a news item is: - render the details > image if there is one - render the organisation > default image if there is one - render a placeholder Organisation here could be one of two types: - Organisation, presented in the primary_publishing_organisation link - WorldwideOrganisation, presented in the worldwide_organisations link The placeholder is also dependent on which type of document and so which type of organisation the content links to. Here we allow the module to render the default image from the worldwide organisation link, when the document is the appropriate type and one is available. Right now this change will not be used as Whitehall currently sets details > image to the default image for worldwide organisation news items, but this is set to change as we want this logic out of the publishing applications and for all related concepts like 'the default news image' to work the same way. With this change, once we do turn the replacement in Whitehall off, everything will continnue to work without change.
The placeholder image and default news image both depend on whether the content item is a world news story.
645b30c
to
822511a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a minor nitpick about the syntax to get the worldwide organisation.
worldwide_organisation = content_item.dig("links", "worldwide_organisations") | ||
worldwide_organisation[0].dig("details", "default_news_image") if worldwide_organisation.present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick where I think first
would be nicer than accessing with a numeric position. The first
method still returns nil
if there's an empty array.
worldwide_organisation = content_item.dig("links", "worldwide_organisations") | |
worldwide_organisation[0].dig("details", "default_news_image") if worldwide_organisation.present? | |
worldwide_organisation = content_item.dig("links", "worldwide_organisations").first | |
worldwide_organisation.dig("details", "default_news_image") if worldwide_organisation.present? |
|
||
def first_primary_publishing_organisation_default_news_image | ||
organisation = content_item.dig("links", "primary_publishing_organisation") | ||
organisation[0].dig("details", "default_news_image") if organisation.present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here as my previous comment.
Unless a user has added a specific news image for a news article, then a default image is retrieved from an associated organisation or worldwide organisation. Currently, the default image is surfaced as an `image` in the details of a news story. However, this is problematic because the default image does not update through dependency resolution when the image is changed on the associated organisation or worldwide organisation. This sets the image as nil if the article has a default image. Government Frontend will render the default news image when the details image is absent (alphagov/government-frontend#3096), allowing us to replicate the functionality we are removing here through link expansion instead.
Unless a user has added a specific news image for a news article, then a default image is retrieved from an associated organisation or worldwide organisation. Currently, the default image is surfaced as an `image` in the details of a news story. However, this is problematic because the default image does not update through dependency resolution when the image is changed on the associated organisation or worldwide organisation. This sets the image as nil if the article has a default image. Government Frontend will render the default news image when the details image is absent (alphagov/government-frontend#3096), allowing us to replicate the functionality we are removing here through link expansion instead.
We considered including default news image as a link instead of relying on ActiveRecord callbacks. However:
|
The logic to render an image for a news item is:
Organisation here could be one of two types:
The placeholder is also dependent on which type of document and so which
type of organisation the content links to.
Here we allow the module to render the default image from the worldwide
organisation link, when the document is the appropriate type and one is
available.
Right now this change will not be used as Whitehall currently sets
details > image to the default image for worldwide organisation news
items, but this is set to change as we want this logic out of the
publishing applications and for all related concepts like 'the default
news image' to work the same way.
With this change, once we do turn the replacement in Whitehall off,
everything will continnue to work without change.
Follow these steps if you are doing a Rails upgrade.