Closed (fixed)
Project:
Metatag
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
14 Sep 2014 at 12:23 UTC
Updated:
27 Jan 2016 at 21:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
traveller commentedAs an example, this article lists all images in the metatag
twitter:image:src. Twitter's Card Validator doesn't get the first picture.My preferred solution would be to list just the first (or any specified) file.
Comment #2
damienmckennaI marked #2338223: Twitter Cards type Gallery support as a duplicate.
Comment #3
attiks commentedI added a new theme function theme_metatag_twitter_cards_single which accepts an optional parameter offset, so the code can define which value to use if multiple values are provided, useful for twitter cards.
Comment #4
damienmckennaThis needs to be handled at the Token level.
Comment #5
attiks commented#4 True, but that means that users will need to know which fields are single value and which are multi value ones, since there's no validation this will be hard for most people. I had to look at the twitter card spec to see which fields are single value.
It would be nice if token has support to select a single value for multi values fields, but I don't have the time right now to write the necessary patches.
Comment #6
attiks commentedI guess this is the related issue in the token issue queue: #1037524: Support array-format tokens in [current-page:query:x] tokens
Comment #7
damienmckennaThe forms fields indicate which of them accept multiple values, though we could improve the UX if needed (maybe add a suffix to the title?).
I need to dig into this.
Comment #8
attiks commentedI searched a bit, and according to #1037524-6: Support array-format tokens in [current-page:query:x] tokens the following should work
[node:field-image:0:file:url], since my field is calledfield_images, I tried[node:field-images:0:file:url]but I got a validation error.Updated: See following comment
Comment #9
attiks commented#8 Strike that, just enable
entity tokenand[node:field-images:0:file:url]works.You need to install Entity and enable both entity and entity_token
Comment #10
attiks commentedI guess this is WAD, but I guess it might be a good idea to mention the existence of Entity tokens and the benefits, I still think adding an option in metatag to automatically select one value if the field is single value is a good improvement.
Comment #11
attiks commented#9 It appears it only works for the first element, using
[node:field-images:1:file:url]does not work for meComment #12
damienmckennaBTW should the first element be element 0 instead of 1?
Comment #13
damienmckennaDuh, sorry, I misread.
Comment #14
damienmckennaComment #15
damienmckennaUpdating the title to better indicate the issue's focus.
Comment #16
mediaformat commentedThis is what works for field collections, if anyone needs a work around.
[node:field-collection-image:0:field_image]
Comment #17
adamps commentedThe comments here helped me figure out my problem. But I'm now a bit confused as to why the issue is still set to "needs work" - it works fine for me.
All you need to do is:
More detailed notes:
So potentially all that is needed is some documentation updates. I've set the component accordingly. There are several image-based metatags, including og:image and image_src. We could clarify the description of each field. Or perhaps some text could be added to the top-level text $form['metatags']['intro_text'].
Comment #18
2phaThanks, #9 worked for 'image_src' metatag for me
Comment #19
jelo commentedI reported similar issues in this thread https://www.drupal.org/node/2623330 all related to multiple values in images, e.g. in which context they are allowed (OG) and not allowed (Twitter?). I think the discussion should be if this module should try to automatically validate where needed, despite relying on tokens to do the bulk of the work, i.e. if an image is used in Twitter Cards, can the module check if multiple values exist and should it automatically limit it to 1 in this case?
Comment #20
damienmckennaWould something like this work? Change metatag.inc from this:
to this:
That'd change image meta tags so that if more than one item was found on a non-multiple meta tag it would only output the first one.
Comment #21
jelo commentedFor Twitter it looks like all cards that were able to handle multiple images have been deprecated as of July 2015:
https://dev.twitter.com/cards/types
In particular, gallery card was removed which could show a number of images. From the descriptions of the remaining cards it sounds as if all only take in one image. In contrast to Facebook which allows a user to pick from multiple images in a preview, I have not seen this with Twitter, i.e. I would think limiting the options to one may be desired at this stage.
We could either focus on providing this option through a token (which would require the person configuring the card to know that multiple images should be limited to 1, but may leave flexibility to decide which image to use) - functionality as provided by entity_token - or make this decision for the person configuring the card and limit to first image by default for Twitter?
Alternatively, we could add instructional text to the image field for Twitter to highlight the need to the user that they should think about multiple image values and that Twitter only expects 1 image, i.e. they should pick a token that only provides a single image.
One related problem with entity_token is though that it does not allow specification of the image style per image. This is important because Twitter has some format requirements for the image and we could tackle this with a specific image style to deliver a correctly formatted image if the token would allow this selection.
Comment #22
maxplus commentedHi,
I used [node:field-images:0:file:url] like #9 in combination of entity_token.
Maybe this could help for using an image style: https://www.drupal.org/project/imagecache_token
Comment #23
damienmckennaSo of course I messed up the code snippet in #20.
I think this patch is what I was thinking of - always explode the value (to turn it into an array) and then only take the first value if the tag doesn't allow multiple items.
Comment #24
damienmckennaComment #25
damienmckennaUpdated patch with some additional comments.
Comment #26
damienmckennaI'd really like to add some tests but I haven't worked on tests for images yet..
Comment #27
damienmckennaCommitted. Please follow up in new issues if there are any further issues with this. Thanks.
Comment #28
damienmckenna