reviewBody always exploded

Created on 13 December 2023, over 1 year ago

Problem/Motivation

In schema_review, if the reviewBody field contains commas, it is always exploded into an array, despite being listed in neverExplode().

Example:

Despite its unimaginative construction, inherent pleasures persist in One Life, but it reeks of all the emotional complexity of an inspirational Facebook video.

"reviewBody": [
   "Despite its unimaginative construction",
   "inherent pleasures persist in One Life",
   "but it reeks of all the emotional complexity of an inspirational Facebook video."
]

This is because the schema for that field sets multiple to TRUE.

 * @MetatagTag(
 *   id = "schema_review_review_body",
 *   label = @Translation("reviewBody"),
 *   description = @Translation("Review body."),
 *   name = "reviewBody",
 *   group = "schema_review",
 *   weight = 11,
 *   type = "string",
 *   secure = FALSE,
 *   multiple = TRUE,
 *   property_type = "text",
 *   tree_parent = {},
 *   tree_depth = -1,
 * )
 */

This means that in processItem() in SchemaNameBase.php, $explode for this field is always set to TRUE, and the logic never proceeds to check neverExplode().

 protected function processItem(&$value, $key = 0) {
    
    if ($key === 0) {
      $explode = $this->multiple();
    }
    elseif ($this->schemaMetatagManager->hasSeparator()) {
      $explode = TRUE;
    }
    else {
      $explode = !in_array($key, $this->neverExplode());
    }

Proposed resolution

I'm not sure why this field is marked as potentially having multiple items. Per the documentation on schema.org, it should just be a simple text field.

So, I'd propose updating the schema to set multiple to FALSE.

If this field is in fact supposed to allow multiple values, the entire logic string in processItem() will need to be reworked instead. This is further complicated by the fact that the $key is not passed to processItem() in the case of simple strings like reviewBody so the array check as written would fail even if that branch of the logic were reached.

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jesss

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