I would like to have a fallback/default image for pages on a site that do not have an image field. To do this, I am including a full image URL as the fallback (https://www.freepress.net/sites/default/files/free_press_metatag.png) and a token ( [node:field_image:entity:field_image:entity:url] )

I tried setting image_src, og_image, and twitter_cards_image to have the value:

"https://www.freepress.net/sites/default/files/free_press_metatag.png, [node:field_image:entity:field_image:entity:url]"

This results in the image_src and twitter card having an invalid URL that contains the comma. The og_image works fine.

<link rel="image_src" href="https://www.freepress.net/sites/default/files/free_press_metatag.png," />
<meta property="og:title" content="Union Says T-Mobile Should Not Get COVID-19 Stimulus Money" />
<meta property="og:description" content="The Communications Workers of America and several advocacy groups argue that Congress should not give T-Mobile money to cover its merger-buildout conditions." />
<meta name="twitter:image" content="https://www.freepress.net/sites/default/files/free_press_metatag.png," />
<meta property="og:image" content="https://www.freepress.net/sites/default/files/free_press_metatag.png" />

If I reverse the order of the URL and the token, the behavior still appears broken, but instead if a page has an image that the token picks up it results in the image src including both URLs and the comma like this:

<link rel="image_src" href="https://www.freepress.net/sites/default/files/covid_map.png, https://www.freepress.net/sites/default/files/free_press_metatag.png" />
<meta property="og:description" content="The coronavirus pandemic has upended life for all of us — and it&#039;s disproportionately impacting some communities, like people of color and people who are incarcerated." />
<meta name="twitter:image" content="https://www.freepress.net/sites/default/files/covid_map.png, https://www.freepress.net/sites/default/files/free_press_metatag.png" />
<meta name="twitter:image:width" content="1400" />
<meta name="twitter:image:height" content="620" />
<meta name="twitter:image:alt" content="Map of COVID-19 outbreak across the globe" />
<meta property="og:image" content="https://www.freepress.net/sites/default/files/covid_map.png" />
<meta property="og:image" content="https://www.freepress.net/sites/default/files/free_press_metatag.png" />

This appears to be a bug to me, but I might be misunderstanding how this works. Looking at this issue (https://www.drupal.org/project/metatag/issues/2809763) it seems like metatag should support multiple values separate by a comma.

CommentFileSizeAuthor
#6 3129710-6.patch647 bytesrokzabukovec
#2 3129710_2.patch541 bytesrokzabukovec

Issue fork metatag-3129710

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

srdtwc created an issue. See original summary.

rokzabukovec’s picture

Status: Active » Needs review
StatusFileSize
new541 bytes

It looks like this is the desired behavior of the Twitter card modules. Every metatag has a property "multiple" which tells the plugin if it should expect multiple values separated by a comma or just treat the input as one value. The default option for "multiple" property is set to false. If you want the behavior you describe you can use my patch. But, again this is not a bug, just the plugin definition option. The maintainer should check if it even makes sense to have multiple values for the image metatag.

damienmckenna’s picture

Title: Multiple images results in trailing comma in URL » Single-value image meta tags do not handle multiple values correctly
Status: Needs review » Needs work
Related issues: +#3067803: Use custom delimiter instead of commas for multiple values

The meta tag definition is correct, the problem is the logic for processing image meta tags that only allow a single value when multiple values are present.

Putting this back to "needs work".

srdtwc’s picture

Are you saying that the module should allow entering a comma separated list, but before it generates the markup on the page it should include only the first available one?

damienmckenna’s picture

Correct.

rokzabukovec’s picture

Status: Needs work » Needs review
StatusFileSize
new647 bytes

I created a patch that checks the presence of a comma separator on a metatag that should only have a single value and then it takes only the first image URL. I think the progress of this issue still depends on the Use custom delimiter instead of commas for multiple values issue. After the custom delimiter issue is fixed we need to replace the delimiter to solve this issue as well.

damienmckenna’s picture

Status: Needs review » Needs work

I think it'd be simpler to just run array_filter() on the string after the explode().

David-Bouzouita made their first commit to this issue’s fork.

damienmckenna’s picture

Status: Needs work » Fixed
Parent issue: » #2994433: Automatically parse URLs from image field tokens

I appreciate everyone's work on this, but it turned out that this was fixed in #2994433: Automatically parse URLs from image field tokens.

Thanks to the powers of d.o, I'm still giving you all issue credit as I appreciate the work you did on this.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.