Having added an image field to a content type, it's being output successfully in the OG and Twitter image tags when using [node:field_image]
.
What I'd like to be able to do is set a default image on the image field and have this output when an image hasn't been added specifically.
Currently, the image metatags are only output when the field is populated on the node in question, rather than displaying the default image as expected.
I'm quite happy to use some kind of workaround, but thought that this would behave as expected out of the box.
Comments
Comment #2
kiwimind CreditAttribution: kiwimind at Torchbox commentedComment #3
kiwimind CreditAttribution: kiwimind at Torchbox commentedBy way of a workaround, we're currently using hook_tokens_alter() in a custom module.
Happy to share thoughts if anyone else gets stuck on this.
Comment #4
DamienMcKennaNeed to get all of the image handling tests ported over from D7 to make sure it works correctly.
Comment #5
DamienMcKennaThis will be at least partly covered by #2628472: Write tests for image handling.
Comment #6
benstjohn CreditAttribution: benstjohn commented@kiwimind Would you be able to post a snippet on how you used hook_tokens_alter() to provide a default image when one does not exist?
Comment #7
kiwimind CreditAttribution: kiwimind commented@benstjohn perhaps I should have just posted them at the time. :)
I'm sorry but I've moved jobs since then so don't have access to the code.
Comment #8
BigEd CreditAttribution: BigEd as a volunteer commentedGuys, I Just had this crop up for an issue I am working on then I worked it out as its not that obvious I thought i would post back, you just need to do this..
Open Graph section > Image URL
[node:field_image:entity:url],[site:url]/sites/default/files/pathtologo.jpg
This will output both values but only show either in the open Graph, I hope this saves you some time faffing about.
Comment #9
idebr CreditAttribution: idebr at iO commentedThe default image is only available when the field is rendered using a formatter. There is Drupal Core issue to apply the default value at the data level that should fix this use case as well: #3005528: Fields' "default value" functionality only works in formatters and widgets, not at the data level and hence not in HTTP APIs