image_src converts to relative link

Created on 23 March 2023, over 1 year ago
Updated 15 December 2023, 7 months ago

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.

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States glynster

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

  • Issue created by @glynster
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    Thank you for reporting the bug.

    Have you tried other image meta tags, e.g. og:image_url, og:image:secure_url, twitter:image, etc?

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    @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?

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    That'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?

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    Sorry I misunderstood what you said. The other metatag field 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.

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    Okay 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">

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    I don't see anything in core related to image_src. Might it come from another module, or maybe the theme?

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    This 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.jpg

    That 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!

  • πŸ‡ΊπŸ‡ΈUnited States glynster

    I also disabled the Schema module just in case it was getting in the way.

  • πŸ‡ΊπŸ‡ΈUnited States kruser

    I'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:

    <link rel="image_src" href="test image.jpg" />  (missing site URL and directory path)
    
    <meta property="og:image" content="https://www.site.org/sites/default/files/test%20image.jpg" /> (works)
    
    <meta property="og:image:url" content="https://www.site.orgtest image.jpg" />  (missing directory path)
    
    <meta property="og:image:secure_url" content="https://www.site.orgtest image.jpg" />  (missing directory path)
    
    <meta name="twitter:image" content="https://www.site.org/sites/default/files/test%20image.jpg" /> (works)
    
  • πŸ‡­πŸ‡ΊHungary junkuncz

    Looks 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.

  • Status changed to Needs review 7 months ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 8
    last update 7 months ago
    111 pass, 2 fail
  • Status changed to Needs work 7 months ago
  • πŸ‡­πŸ‡ΊHungary junkuncz

    Upps! :( 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).

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 8
    last update 7 months ago
    111 pass, 2 fail
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 8
    last update 7 months ago
    111 pass, 2 fail
  • πŸ‡¦πŸ‡ΉAustria fago Vienna

    https://www.drupal.org/node/640498/qa β†’ has the same 2 fails, but shows green tests on 7.4. So let's try that.

    Patch seems simple enough, so let's do this.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.6
    last update 7 months ago
    Composer require failure
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.4 + Environment: PHP 7.4 & MySQL 8
    last update 7 months ago
    Composer require failure
  • πŸ‡­πŸ‡ΊHungary 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.

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    I'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 β†’

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    The 2.0.x tests are currently failing, so I'm removing the Devel and WebProfiler tests: πŸ“Œ Remove Devel, WebProfiler tests Needs review

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 8
    last update 7 months ago
    109 pass
  • Status changed to Needs review 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    I committed #3408825 so the tests for this should pass now.

Production build 0.69.0 2024