Problem/Motivation
When attempting to access the JSON-LD Schema configuration form (for example:
/admin/structure/types/manage/article/json_ld_schema), the following error occurs:
Drupal\json_ld_schema_ui\Schemaorg\ParseException: No definitive root could be determined
in Drupal\json_ld_schema_ui\Schemaorg\Parser->getRoot()
(line 238 of modules/contrib/json_ld_schema_ui/src/Schemaorg/Parser.php).
Root Cause
The Parser::getRoot() method assumes there will be only one root class in the Schema.org vocabulary (i.e., a class with no parent classes).
However, when parsing the latest Schema.org JSON-LD source https://schema.org/version/latest/schemaorg-current-https.jsonld the parser identifies 80 root classes instead of one.
These additional roots come from external vocabularies included in the Schema.org source (e.g., bibo, foaf, gs1, unece, cmns, fibo, etc.) that are not subclasses of schema:Thing.
Steps to reproduce
1. Install json_ld_schema_ui 1.0.5 in Drupal 11
2. Configure the module to use the default schema.org source: https://schema.org/version/latest/schemaorg-current-https.jsonld
3. Navigate to a content type's JSON-LD Schema configuration page (e.g., /admin/structure/types/manage/article/json_ld_schema)
4. Observe the ParseException error
Proposed resolution
Instead of assuming there is only one root class, update Parser::getRoot() to:
• Allow multiple roots
• Look specifically for schema:Thing
• Return it if found
• Only throw an exception if schema:Thing is not among the roots
Issue fork json_ld_schema_ui-3568227
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
Comment #3
gxleano commentedComment #6
gxleano commented