TypeError in `SchemaDotOrgSchemaTypeManager::isSubTypeOf` due to incorrect handling of `additionalType` in `schemadotorg_additional_type.module`

Created on 23 May 2024, 7 months ago
Updated 11 June 2024, 7 months ago

Problem/Motivation

After updating the Schema.org module to the last dev version, an error occurs when viewing specific content types. The error message is as follows:

The website encountered an unexpected error. Try again later.

TypeError: Drupal\schemadotorg\SchemaDotOrgSchemaTypeManager::isSubTypeOf(): Argument #1 ($type) must be of type string, array given, called in /var/www/html/web/modules/contrib/schemadotorg/modules/schemadotorg_additional_type/schemadotorg_additional_type.module on line 67 in Drupal\schemadotorg\SchemaDotOrgSchemaTypeManager->isSubTypeOf() (line 124 of modules/contrib/schemadotorg/src/SchemaDotOrgSchemaTypeManager.php).
schemadotorg_additional_type_schemadotorg_jsonld_schema_type_entity_alter() (Line: 149)

This issue occurs because the `schemadotorg_additional_type_schemadotorg_jsonld_schema_type_entity_alter` function does not properly handle cases where the `additionalType` property is an array instead of a string.

Proposed Resolution

The proposed solution is to update the `schemadotorg_additional_type_schemadotorg_jsonld_schema_type_entity_alter` function to handle both string and array values for the `additionalType` property. The updated function will iterate over the array values and check if each value is a valid subtype.

Steps to Reproduce

  1. Update the Schema.org module to the last dev version
  2. View a content type that utilizes the `additionalType` property.
  3. Observe the TypeError in the error logs.

Patch

The attached patch modifies the `schemadotorg_additional_type.module` file to properly handle both string and array values for the `additionalType` property.

Additional Information

  • Drupal version: 10.2.6
  • Schema.org module version: 1.0.0-dev

Review

Please review the attached patch and consider it for inclusion in the next release of the Schema.org module. Thank you!

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡°πŸ‡¬Kyrgyzstan dan_metille

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