Add a smart [node:share-image] token with option for a fallback URL for node social media tokens when the media field is empty

Created on 28 July 2024, about 2 months ago
Updated 9 September 2024, 10 days ago

Problem/Motivation

Content editors sometimes leave media fields empty when creating or editing nodes. This results in tokens that rely on these fields failing to generate media URLs.

Old used tokens are too complicated to use by Editors or Content Admin.
The logic of nesting is not allowing us to have a fullback in the right way.

  • [node:field_media:entity:social_large]
  • [node:field_media:entity:social_medium]
  • [node:field_media:entity:social_small]

Steps to reproduce

Create a content type with a media field (e.g., field_media).
Add a node of this content type without filling in the media field.
Use the following token [node:field_media:entity:social_large] in metatag for the content type.

Proposed resolution

Get the social share image for the node ( Smart token )
[node:share-image]
Check if the field media has data, then bring it’s image ( social_large ) size
else the fullback share image from the active theme.

-- this should work with field_media

  • if no field_media, check for a field_image
  • if no field_image, check for a field_video
  • if no field_video .. get the fallback share-image from the theme
( this if no field data and if no field in the content type )
Watch this video
β†’
  • Check if a media field in a node is empty and return a fallback URL if it is.
  • Change the logic to Implements hook_token_info()
  • Change our logic on the used tokens with tokens info

Allow for other variations.

[node:share-image:field_image]
Check if the field image has data, then bring it’s image ( social_large ) size
else the fullback share image from the active theme.

[node:share-image:field_media]
Check if the field media has data, then bring it’s image ( any selected field_ entity reference to media ) ( social_large ) size
else the fullback share image from the active theme.

[node:share-image:field_media:social_large]
Check if the field media has data, then bring it’s image ( any selected field_ entity reference to media ) social_large size
else the fullback share image from the active theme.

[node:share-image:field_media:social_medium]
Check if the field media has data, then bring it’s image ( any selected field_ entity reference to media ) social_medium
else the fullback share image from the active theme.

[node:share-image:field_media:social_small]
Check if the field media has data, then bring it’s image ( any selected field_ entity reference to media ) social_small
else the fullback share image from the active theme.

Remaining tasks

  • βœ… File an issue about this project
  • βœ… Addition/Change/Update/Fix to this project
  • βœ… Testing to ensure no regression
  • βž– Automated unit/functional testing coverage
  • βž– Developer Documentation support on feature change/addition
  • βž– User Guide Documentation support on feature change/addition
  • βž– UX/UI designer responsibilities
  • βœ… Accessibility and Readability
  • βœ… Code review from 1 Varbase core team member
  • βœ… Full testing and approval
  • βœ… Credit contributors
  • βœ… Review with the product owner
  • βœ… Update Release Notes and Update Helper on new feature change/addition
  • βœ… Release varbase-10.0.1 β†’ , varbase_media-10.0.4 β†’

Varbase update type

  • βœ… No Update
  • βž– Optional Update
  • βž– Forced Update
  • βž– Forced Update if Unchanged

User interface changes

  • N/A

API changes

  • N/A

Data model changes

  • N/A

Release notes snippet

  • Issue #3464179 β†’ by Ammar_Jeetawi β†’ : Added a smart [node:share-image] token with option for a fallback URL for node social media tokens when the media field is empty
πŸ“Œ Task
Status

Fixed

Version

10.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024