I tried to configure my og:image field as follows:
[node:field_myimage],https://some-static-fallback-image.png
On nodes that feature an image, everything works as expected.
On nodes that have no image, metatag will write the following html:
The comma prepending the url prevents FB to scrape my image. I guess there should be no comma in this case, as the first element is empty
Is there an alternative way to define a fallback image? I found a ticket for an older version, but the solution doesn't seem to have made it in the D8 port?
Comments
Comment #2
damienmckennaI think adding an array_filter() inside MetaNameBase::parseImageURL() might help fix this. Lets also add a test to make sure it does.
Comment #3
adamps commentedHere is an attempt at a patch (sorry no tests but a hopefully it's a good start). I started with the suggestion from #2, but things got more complicated!
strip_tags($value) != $valuebecause I couldn't see a neat way to keep it, and I guess it won't make much difference. In fact strip_tags is not trivial so I may have speeded things up! The original code called strpos before checking for tags anyway so things were hardly optimal.Comment #4
damienmckennaOut of interest, does this solve the problem for you?
Comment #5
adamps commented@DamienMcKenna Thanks for spending more time on this one.
Your patch in #4 doesn't solve the whole problem. Your patch is exactly what I expected from your comment in #2. In #3, I mentioned 4 extra problems that I found. I'll explain a little more.
The most important test case is if all of the components are empty, which your patch doesn't handle.
strip_tags($value) == $valueso the array_filter is never called. My resolution (first bullet in #3) was to delete the lineif (strip_tags($value) != $value) {because the contained code seems safe to run even if there are no tags. I think that this line is an attempted performance improvement that more often makes things slower - on many sites the tag will expand to valid images and so calling strip_tags is quite expensive and a waste of time.Then I spotted two separate bugs that aren't actually a problem on my site, but I thought it might help others to fix them.
If you like I can reroll my patch to exclude these two separate bug fixes.
Comment #6
damienmckennaThanks for the extra explanation. Lets split off the separate bugs and I'll try to help with tests to cover this bug.
Comment #7
adamps commentedThanks, here is the revised patch as requested in #6
Comment #8
damienmckennaI'm splitting off the output cleanup to #2911435: Streamline the HTML output logic.
Comment #9
damienmckennaThe bare change.
Comment #10
adamps commented@DamienMcKenna many thanks for your ongoing work. Is the status "needs review" still true? The new patch is only one line and looks sensible. I guess that the next step is covered by the tag "needs tests".
Comment #12
damienmckennaAt this point I'm fine with the minor fix, the tests will be done in #2628472: Write tests for image handling.
Thanks for your work on this!
Comment #13
aspilicious commentedTwitter card image is still broken, even after this patch.
Og:image seems to work.
Comment #14
damienmckenna@aspilicious: Please open a new issue and describe the problem you're seeing with the twitter image tag. Thanks.
Comment #16
smazJust as a note, the twitter card image is broken as twitter doesn't like there to be a comma separated list of images.
See https://www.drupal.org/node/2628934 for handling multiple value metatags (like og:image) that would fix that.