og:image token with JPEG image_style fails on a source WebP image in a nested Paragraphs > Media structure
Problem/Motivation
When setting an og:image meta tag, we are trying to source the image from a deeply nested entity structure: Node > Paragraph Field > Paragraph Entity > Media Reference Field > Media Entity > Image Field.
The original source image is uploaded in WebP format. To ensure compatibility with all social media platforms (like LinkedIn), we are using an image_style processor to convert the WebP image to a JPEG.
While a token for the original WebP image URL works, adding the JPEG-conversion :image_style processor to the token causes it to fail completely. This results in no og:image tag being rendered in the HTML at all.
We have confirmed through direct URL access that the image style itself works correctly: visiting the styled URL successfully generates and displays a JPEG from the WebP source. The issue seems to be with the Metatag module's ability to process a token that is both deeply nested and invokes an image style that performs a format conversion.
Steps to reproduce
1. Create the Entity Structure:
o Create a Media Type (e.g., "Social Image", machine name: social_image) with an Image field (field_media_image).
o Create a Paragraph Type (e.g., "SEO Meta", machine name: seo_meta) with a Media reference field (field_social_media_image) that targets the "Social Image" media type.
o Create a Content Type (e.g., "Basic Page") with a Paragraph field (field_seo_paragraph) configured to accept the "SEO Meta" paragraph.
2. Create an Image Style:
o Create a new image style (e.g., "Social Share JPEG", machine name: social_share_jpeg) that includes a "Convert to JPEG" effect.
3. Configure Metatag:
o Edit the Metatag defaults for the "Basic Page" content type.
o Set the og:image field to use the following token: [node:field_seo_paragraph:entity:field_social_media_image:entity:field_media_image:entity:image_style:social_share_jpeg]
4. Create Content:
o Create a new "Basic Page" node.
o Add an "SEO Meta" paragraph to the field_seo_paragraph.
o In the paragraph, upload a WebP image and add it as a published media item to the field_social_media_image field.
o Ensure the node, the paragraph, and the media item are all published.
5. Observe the Result:
o View the HTML source of the newly created page as an anonymous user.
Expected Result
The page's HTML should contain a valid og:image meta tag pointing to the URL of the styled JPEG image, which was successfully converted from the WebP source. Example:
Actual Result
No og:image meta tag is rendered in the page's HTML. The token appears to fail and returns an empty value.
Additional Information
• We have confirmed that a simpler token ending in :url (without the image style) does work and outputs the URL of the original WebP image.
• We have confirmed that directly visiting the URL for the styled image correctly triggers the conversion and displays the final JPEG in the browser.
• We have confirmed that the "Anonymous" user role has permission to view published Paragraphs and Media.
• This issue points to a potential problem in how the token system passes the entity context through multiple levels of nesting when an image style processor is invoked, specifically when that processor involves a format conversion (WebP to JPEG).
Proposed resolution
Turns out that it is not the nested structure, but the way the image style is referenced
Example that does not work:
... field_media_image_1:entity:image_style:social_share_jpeg]
Example that does work (as in the parent case):
... field_media_image_1:social_share_jpeg:url]
Remaining tasks
Follow the parent cases explanation and add it asap to the gui.
User interface changes
See parent case.
API changes
Data model changes