If Q&A array is empty, we shouldn't render the object at all

Created on 19 November 2024, 29 days ago

Problem/Motivation

If Q&A array is empty, we shouldn't render the object at all. If we use a token for acceptedAnswer, and that token is empty, we render e.g.:

 {
            "@type": "FAQPage",
            "mainEntity": {
                "@type": "Question",
                "acceptedAnswer": {
                    "@type": "Answer"
                }
            }
        }

Steps to reproduce

Proposed resolution

Override SchemaQAPageMainEntity::output() like

  public function output(): array {
    $result =  parent::output();
    if (!isset($result['#attributes']['content'][0])) {
      return [];
    }
    else {
      return $result;
    }
  }

Remaining tasks

Patch.

User interface changes

API changes

Data model changes

None.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇬🇧United Kingdom stefank

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024