Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motiviation
When an Image field field_image
is provided a default value on the field settings, but on the node no image is selected for the field, then the url, height, and weight attributes are not displayed with the metatags.
Replication steps:
- Add
field_image
to the Article content type - Provide a default value for the field under field settings
- Create a new node of type Article
- Populate the field by selecting an image from the media library
- Setup the Schema.org Article meta tag so that the
[node:field_image:large:url]
is set as the url under any ImageObject - Save and view the page to observe the correct attributes added to the page
- Edit the page again and remove the selected image
- Save and view the page to observe the url attribute is missing from the ImageObject
Current meta tag output
"image": {
"@type": "ImageObject",
"representativeOfPage": "True"
},
Expected meta tag output (with no image selected)
"image": {
"@type": "ImageObject",
"representativeOfPage": "True",
"url": "https://some-default/url/large/cloud.jpg?itok=W4d08z8M",
"width": "400",
"height": "260"
},
Expected meta tag output (with image selected)
"image": {
"@type": "ImageObject",
"representativeOfPage": "True",
"url": "https://selected-image/url/large/cloud.jpg?itok=W4d08z8M",
"width": "400",
"height": "260"
},
Proposed Solution
- Add validation to check if image is populated then use the image. If not, then retrieve the default image from field setting
- If we cannot get the default image, then do not display the ImageObject attribute
Remaining tasks
- Add patch to allow for retrieving the default value when image is empty
Comments
Comment #2
drup16 CreditAttribution: drup16 commentedComment #3
drup16 CreditAttribution: drup16 commentedUpdating version as issue still exists in v8.x-1.3
Comment #4
drup16 CreditAttribution: drup16 commentedComment #5
drup16 CreditAttribution: drup16 commentedComment #6
drup16 CreditAttribution: drup16 commentedComment #7
DamienMcKennaIs this still a problem with v8.x-2.x or 3.0.x? The 8.x-1.x branch is no longer supported. Thank you.