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

Created on 23 May 2024, 6 months ago
Updated 11 June 2024, 5 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 sahaj

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

Merge Requests

Comments & Activities

  • Issue created by @sahaj
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    I am trying to understand when is the additionalType field an array.

    Does the additionalType field on your site support multiple values?

  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    I am inclined to only support additionalType being a simple string value and ignoring it when it is an array.

  • πŸ‡°πŸ‡¬Kyrgyzstan sahaj

    Actually, I noticed the issue on a 'Service' type. But what was strange, is that the Schema.org additional type wasn't enabled.

  • πŸ‡°πŸ‡¬Kyrgyzstan sahaj

    Just reverted the patch to check further. And I can confirm that Schema.org additional type isn't enabled for 'Service' content type.
    However, it has a select box for the Type (that I maybe forgot to delete at some point). But even deleting that field alone doesn't help.

  • πŸ‡°πŸ‡¬Kyrgyzstan sahaj
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    I am pretty sure that for the local setup, the existing additionalType is a multiple-value field, which is fine but triggered the error.

  • πŸ‡°πŸ‡¬Kyrgyzstan sahaj

    Honestly I don't know. Since the time I'm using Schema.org Blueprints, I should admit that I'm still not mastering all the sides of it!
    For instance, I'm still sometime struggling while adding fields or paragraphs that don't exactly fit the schema.org structure. But the concept and realization is so powerful... Maybe it is too soon, but I was wondering if it would be possible and an interesting idea to connect with such module as AI Interpolator β†’ . This module is for instance able to create content types and fields from a PDF, using AI. The pity is that it's don't follow the schema.org structured hierarchy. Would it be difficult?

  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    I'm still not mastering all the sides of it!

    Neither am I, which is why the module is still in alpha with major changes still happening.

    My organization is not currently looking into AI integration. Ideally, a good AI project would look at a page's JSON-LD.

  • Pipeline finished with Skipped
    6 months ago
    #184407
  • Status changed to Fixed 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024