Adding microdata support to fields

Microdata can be placed in the HTML tags around fields so that the data can be easily extracted into a JSON object. Microdata is very specific about where microdata attributes should be placed for different HTML tags, so sometimes the field formatters need to place the microdata themselves.

In order to enable microdata output for your fields, you have to:

  1. Enable microdata configuration
    Let microdata module know whether your field has microdata integration and/or whether your field has any properties that have microdata integration. Microdata module will then add a form section to the field settings so the user can specify which microdata terms they want to use for the field.
  2. Place microdata attributes in field formatter
    Based on the user's specifications, a microdata attributes array will be attached to the entity. This array is nested by field name. Your field formatter is responsible for placing the field's microdata attributes in the HTML that the formatter returns.

Additionally, you may want to:

  1. Write automated tests for microdata
  2. These can ensure that your microdata output doesn't break when changes are made to the formatter code.

Enable microdata configuration

Microdata can be enabled for fields, field properties, or both.

Place microdata attributes in field formatter

For many fields and field properties, the field formatter output must be altered to include the microdata properties.

Write automated tests for microdata

To ensure that changes to field formatter code don't break the microdata integration, you may want to write an automated test. Microdata

Guide maintainers

linclark's picture