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.

Command icon 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

stefank created an issue. See original summary.

stefank’s picture

Status: Active » Needs review

guiu.rocafort.ferrer made their first commit to this issue’s fork.

guiu.rocafort.ferrer changed the visibility of the branch 3488419-dont-render-empty-qa-array to hidden.

guiu.rocafort.ferrer’s picture

Status: Needs review » Needs work

The test needs to be updated.