We are using a custom content type and have metatags set up as needed.
Either setting default or on a per content type basis the following occurs:
image_src: '[node:bsp_header:entity:bsp_media:entity:field_media_image]'
Returned metatag:
image_src: '/link-to-image'
However if the same token is added to og:image:
og:image: '[node:bsp_header:entity:bsp_media:entity:field_media_image]'
Returned metatag:
org:image: 'site-url/link-to-image'
Also if you add [site:url] to image_src it will be stripped out as well. No workaround ATM.
It would appear that image_src will always return a relative url path.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | SCR-20230323-mukq.png | 29.29 KB | glynster |
Issue fork metatag-3349990
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
damienmckennaThank you for reporting the bug.
Have you tried other image meta tags, e.g. og:image_url, og:image:secure_url, twitter:image, etc?
Comment #3
glynster commented@DamienMcKenna
Adding og:image_url or og:image:secure_url in the image_src field unsets the tag altogether. I assume this could be the order in which they are generated? Advanced first
URLS that render:
[node:url]
[site:url]
If I add the following:
[site:url][node:bsp_header:entity:bsp_media:entity:field_media_image]Returned metatag:
image_src: '/link-to-image'But added with just the [site:url]
image_src: 'site-url'What else can I supply?
Comment #4
damienmckennaThat's weird - adding a value to og:image:url or og:image:secure_url shouldn't affect og:image at all. Are you using any other modules that relate to OpenGraph?
Comment #5
glynster commentedSorry I misunderstood what you said. The other metatag fields all work as they should including og:image_url, og:image:secure_url, twitter:image. The issue is isolated to the advanced img_src. Somehow that is being adjusted.
We are not using any other additional modules that relate to OpenGraph. Again the issue is related only to the advanced (Generic) metatag img_src section. Please see screenshot.
Comment #6
glynster commentedOkay so I think this might be a Drupal core issue?
it is a link and not meta in the head:
<link rel="image_src" href="/sites/default/files/2023-03/header_locations.jpg">Comment #7
damienmckennaI don't see anything in core related to image_src. Might it come from another module, or maybe the theme?
Comment #8
glynster commentedThis is definitely related to metatag as the url always updates when I update the Advanced image field within meta. I just set core Claro theme and the same result 'realtive url'. However in the global metatag section we have:
[site:url]sites/default/files/2023-03/organization.jpgThat renders fine as an absolute. If you add 2 tokens then it strips the [site:url]. What is odd is that if I add this to the other image urls all is good.
Sorry not helping much am I!
Comment #9
glynster commentedI also disabled the Schema module just in case it was getting in the way.
Comment #10
kruser commentedI'm seeing weird results with this. For example, using this same token in all the image meta fields: [node:field_social_media_image]
I get different results in the output:
Comment #11
junkunczLooks like the reason of wrong image_src attribute is an incomplete Plugin annotation. Setting the "absolute_url" = TRUE gives the ability to output() function (/src/Plugin/metatag/Tag/MetaNameBase.php line 529 in version 2.0.0) to build an absolute url.
Patch is attached.
I don't know what about og:image:url and og:image:secure_url most probably it's a different issue.
Comment #12
junkunczComment #14
junkunczUpps! :( Unfortunately I have no time to fix the tests and I'm quite sure it's not because of this one line change. (Error: Call to undefined method PhpParser\Node\Name::getParts() -> seems like something is missing there).
Comment #15
fagohttps://www.drupal.org/node/640498/qa shows also two fails at 1.x, but shows green tests on 7.4. So let's try that.
Patch seems simple enough, so let's do this.
Comment #16
junkuncz"drupal/metatag dev-2.0.x requires php >=8.0 -> your php version (7.4.28) does not satisfy that requirement."
Looks like no chance without php8.
Comment #17
damienmckennaI'm rerunning the 2.0.x tests as they haven't ran in a while, it seems like they stem from the WebProfiler tests, which I'm considering removing anyway; we'll see what they say shortly: https://www.drupal.org/pift-ci-job/2824531
Comment #18
damienmckennaThe 2.0.x tests are currently failing, so I'm removing the Devel and WebProfiler tests: #3408825: Remove Devel, WebProfiler tests
Comment #19
damienmckennaI committed #3408825 so the tests for this should pass now.
Comment #21
taran2lComment #24
damienmckennaI'm a little surprised at this test failure:
Comment #25
damienmckennaComment #26
taran2lI think it's because XSS string is discraded as not correct URL ... and there is no image_src metatag at all.
I think the options are:
Comment #28
damienmckennaCommitted. Thank you.
Comment #30
taran2lThanks