backdrop-contrib / metatag

Add structured metadata, aka "meta tags", for various pages on your site.
GNU General Public License v2.0
3 stars 15 forks source link

Multi-valued image field tokens don't work properly #17

Closed ghost closed 5 years ago

ghost commented 6 years ago

I've just started using this module, but I noticed an issue when using a token for a multi-valued image field in the og:image tag. It output an empty tag (e.g. < />) which actually displayed on the node (not pretty). Using a single-value field works properly though.

I may be able to test this properly and/or provide more info later, but just starting this issue for now.

ghost commented 6 years ago

So as per http://ogp.me/#array, tags with multiple values are output separately (like duplicates, almost). This module isn't processing multiple values currently, so here's the code to make it do so (no PR sorry):

This https://github.com/backdrop-contrib/metatag/blob/1.x-1.x/metatag.module#L2079 needs to change to this:

else {
  // Account for multi-valued tags.
  if (!isset($data['#tag']) && !empty($data[0])) {
    foreach($data as $delta => $subdata) {
      backdrop_add_html_head($subdata, 'metatag_preprocess_page-' . $tag . '-' . $delta);
    }
  }
  else {
    backdrop_add_html_head($data, 'metatag_preprocess_page-' . $tag);
  }
}
ghost commented 6 years ago

Ok, finally made a PR.

laryn commented 5 years ago

RTBC from me. I was trying to track down why I was getting empty tags in the header and it was due to an image field with more than one value. This was also giving these warnings in the log:

Notice: Undefined index: #tag in theme_head_tag() (line 2452 of /path/core/includes/theme.inc).

The PR above fixes it.

jenlampton commented 5 years ago

Nice, thanks to both of you!