Problem/Motivation
Currently the Free Schema.org tree can only be defined per entity: editors have to build (or import) the tree on every node or taxonomy term. On sites with many entities of the same bundle this is repetitive and error-prone, even though the structure is usually the same for all of them (e.g. every `event` node is an `Event` with the same properties, and every term of the `topics` vocabulary is a `DefinedTerm` or `CollectionPage`), and only the values change.
Since tree values already accept tokens (`[node:title]`, `[term:name]`, `[node:url:absolute]`...), a single tree defined once per bundle would be enough to produce correct JSON-LD for all its entities.
Proposed resolution
Add a bundle-level **default tree**, configurable for any fieldable entity bundle (node types, vocabularies and other content entity bundles):
- Add a "Free Schema.org" section to the bundle edit form (e.g. `/admin/structure/types/manage/{type}`, `/admin/structure/taxonomy/manage/{vocabulary}/overview`), using the same tree editor widget (type/property suggestions, JSON-LD import, token browser).
- Store the default tree as a third-party setting of the bundle config entity (`free_schema` key), so it is exportable with configuration management and translatable via config translation.
- At render time, the JSON-LD for an entity is resolved as follows:
- If the entity has its own value in a Free Schema.org field, use it (current behaviour).
- Otherwise, if its bundle has a default tree, use it, replacing tokens with the current entity.
- Otherwise, do nothing (other JSON-LD on the page is left untouched).
- The default tree replaces every other JSON-LD on the page, exactly like a per-entity tree.
- Editing the default tree requires the existing restricted permission (or a new "Administer free Schema.org defaults" permission).
- Optionally, show the inherited default as a read-only preview / starting point in the entity widget, so editors can see what will be printed and copy it to override it.
Issue fork free_schema-3632333
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 #6
jasa commented