Module Description
This module has a single goal: provide developers with a very simple toolkit for implementing structured data according to the schema.org vocabulary.

When providing structured data as part of your website, there are two considerations:


* The namespace (or vocabulary) to define your structured data according to.
* The format you provide that structured data in.

This module is opinionated about both and supports the most widely recognised namespace (schema.org) and the JSON LD format. This module also provides no UI and is designed as a toolkit for developers to implement structured data. Creating structured data that is useful and validates against the sometimes strict requirements outlined by search engines, is not easy. This is a task that is often delegated to developers as opposed to site builders or content admins.

Using a tool such as the RDF module in core, or other UI based solutions have some of the following caveats:


* They assume a relationship between Drupal entities/fields and structured data vocabularies.
* They intersperse this relationship throughout the theme layer.

Both of these factors make implementing structured data very difficult. Drupal entities and fields are modelled on the basis of providing useful tools for content authoring. For example paragraph bundles may serve as the container for content spread across across many entities that are represented very differently in a structured vocabulary.

Additionally lots of metadata required by particular structured entities simply doesn't exist as part of an entity field. Most articles don't contain an explicit "publisher", this information is usually assumed and derived from the organisation that owns the website itself.

The approach of defining this relationship in markup is also typically very fragile. As markup is moved, changed, altered, preprocessed, reliable ways to add attributes to this markup are lost. A coupling between markup and the structured data creates undue complexity with very little benefit.

The solution: plugins that represent an item of structured data defined using a schema.org builder object:

/** * @JsonLdEntity( * label = "Aussie Pub", * id = "aussie_pub", * ) */ class AussiePub extends JsonLdEntityBase { /** * {@inheritdoc} */ public function isApplicable(EntityInterface $entity, $view_mode) { return $entity->getEntityTypeId() === 'node' && $entity->bundle() === 'pub'; } /** * {@inheritdoc} */ public function getData(EntityInterface $entity, $view_mode): Type { return Schema::barOrPub() // Values based on entity fields. ->name($entity->label()) ->description($entity->field_body->processed) // Some computed value based on another relationship. ->aggregateRating([ Schema::aggregateRating()->ratingValue(compute_pub_rating($entity)), ]) // Hard-coded values fundamental to all items. ->servesCuisine('Pub Grub') ->currenciesAccepted(['AUD']); } } Using this approach, structured data definitions are completely decoupled, are easy to author and have complete flexibility for defining properties.

This module ships with two plugin types:


* JsonLdEntity: Structured data that can appear when an entity is rendered.
* JsonLdSource: Structured data that can appear globally, not attached to a particular entity.

Project Usage
368
Creation Date
Changed Date
Security Covered
Covered By Security Advisory
Version Available
Production
Module Summary
This module provides a simple toolkit for implementing structured data according to the schema.org vocabulary.
Data Name
json_ld_schema

OPENAI CHATBOT

OPENAI CHATBOT

14:31:00
Generic Chatbot
Hi, I'm a Drupal module expert powered by OpenAI, answering your questions about the Drupal module ecosystem. How can I be helpful today? Please note that we will log your question.