Currently, when an imagefield based token is used for the OG:Image metatag, the resulting metatag is output something like this (sanitized value from client site):

<meta property="og:image" content=" <img src="http://www.example.com/sites/default/files/sys/en/page/image/xxxx-contact-us-teaser-en_0.jpg" width="2048" height="750" alt="Contact Us" title="Contact Us" typeof="foaf:Image" />

I spoke about it with Damien and he said the D7 version has logic to pull out the URL that needs to be ported to D8. I'd be willing to give it a whirl but not sure how soon I'll be able to so I'm leaving this unassigned for now.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Michelle created an issue. See original summary.

DamienMcKenna’s picture

Lets add this to beta2.

DamienMcKenna’s picture

There are two parts to how this is handled in D7 - a) any meta tag that has the 'image' attribute set to TRUE tells the output generation to b) grep the output for any image tags.

Michelle’s picture

Here is a patch that fixes the issue similar to D7 but I have a couple concerns:

  • Is output the best place to do this? Should it maybe be done right away when the value is set so that value() returns just the URL?
  • I can't figure out how field tokens are working at all for the client. I initially started working on this on a vanilla 8.0 site and it the field tokens weren't available. I did a little searching through the core issues and all I found was some old issues that indicate field tokens aren't in core, yet. It isn't due to the contrib Token module as Metatag doesn't make use of that, yet, and the client doesn't have it installed. So I'm baffled on how it works for them but not on a vanilla install.
Michelle’s picture

As for the field token mystery, it turns out that Token _is_ installed on the client's site and it just didn't come up in the filter for some reason. So the trick to getting field tokens to work is to have contrib Token installed plus this patch: #2543756: Use renderPlain() in field_tokens() . This works despite the fact that Metatag is using the core token rendering and _not_ the contrib Token version, which I wasn't expecting.

So, to test this patch:

  • Install Metatag _and_ Token.
  • Apply this patch to Token.
  • Add an image field to a node type.
  • Add a metatag field to that same node type.
  • Set OG:Image to use [node:field_yourimagefield] (replace field_yourimagefield with the actual field name)
  • View the source and the OG:Image metatag should just be a link to the image, not the whole HTML provided by the image field.
DamienMcKenna’s picture

Title: OG:Image - Port ability to parse out URL from imagefield token » Parse image fields for image URLs
Component: Open Graph » Code
DamienMcKenna’s picture

DamienMcKenna’s picture

Status: Needs review » Fixed

Committed.

juampynr’s picture

I don't understand the need of the "multiple" property. @Michelle, can you explain it, please?

Michelle’s picture

It was in D7 and used in the code I ported so I ported it as well. I assume it's needed to provide multiple images to choose from like when you share a gallery on Facebook and you can scroll thru and decide which image to represent.

DamienMcKenna’s picture

Some of the meta tags allow for multiple tags, some don't, so we have to handle that.

DamienMcKenna’s picture

And yes, we need to build out the functionality for supporting multiple values (I'd forgotten about it).

DamienMcKenna’s picture

I've added another issue to finish the support for 'multiple' tags: #2628934: Full support for meta tags that allow multiple values

juampynr’s picture

Thanks for the explanation!

DamienMcKenna’s picture

Status: Fixed » Closed (fixed)

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