If SchemaArticleImage url is empty, we shouldn't render the object at all

Created on 6 February 2023, over 1 year ago
Updated 20 June 2023, over 1 year ago

Problem/Motivation

IMHO if SchemaArticleImage url is empty, we shouldn't render the object at all. If we use a token for url, and that token is empty, we render e.g.:

            "image": {
                "@type": "ImageObject",
                "representativeOfPage": "True",
                "width": "499",
                "height": "376"
            },

In SchemaMetatagManager we have logic to avoid those situations, skipping data if @type is the only value set, but that doesn't cover cases like this one, where more than @type is provided, but still the object has no semantic meaning at all without a defined property.

Steps to reproduce

1. Map image url to a field image with an image style and absolute url.
2. Hardcode width and height because we used an image style defining width and height, and representativeOfPage because we know which value we want there.
3. Don't have an image in our content.

Proposed resolution

Override SchemaArticleImage::output() like

  public function output() {
    $result =  parent::output();
    if (empty($result['#attributes']['content']['url'])) {
      return '';
    }
    else {
      return $result;
    }
  }

Remaining tasks

Patch. Tests?

User interface changes

If no url, no image object is rendered.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024