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

Fields

Sometimes fields are simple, without properties. For example, a text field (not long text, but regular textfield) doesn't have any additional properties. The value is simply the text string.

To enable microdata for such a field, you only need to add two pieces of information to the field's array in hook_field_info:

  • microdata — a boolean which indicates whether this field has microdata integration
  • property_type — an Entity Property API data type. The appropriate microdata type is inferred from this.

In the example of the text field, the following code would enable microdata configuration, and would provide the additional field configuration options as shown below.

function hook_field_info() {
  $info['text'] => array(
    ...
    'microdata' => TRUE,
    'property_type' => 'text',
  );
  return $info;
}

Only local images are allowed.

Field properties

Some fields are more complex, like a Link field which has a text value and an href value. These distinct pieces of data within a field are called properties.

To enable microdata for field properties, you only need to add two pieces of information to the field's array in hook_field_info:

  • property_type — see above. This should be a property type that can contain other properties, such as a struct
  • property_callbacks — A function to declare the same type of information about the properties that we've declared about the fields above.
  • microdata — a boolean which indicates whether this field has microdata integration
function link_field_info() {
  return array(
    'link_field' => array(
      ...
      'property_type' => 'field_item_link',
      'property_callbacks' => array('link_field_property_info_callback'),
    ),
  );
}

function link_field_property_info_callback(&$info, $entity_type, $field, $instance, $field_type) {
  $property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$field['field_name']];

  $property['property info'] = array(
    'title' => array(
      'type' => 'text',
      'label' => t('The title of the link.'),
      'microdata' => TRUE,
    ),
    'url' => array(
      'type' => 'uri',
      'label' => t('The URL of the link.'),
      'microdata' => TRUE,
    ),
  );
  if ($instance['settings']['title'] == 'none') {
    unset($property['property info']['title']);
  }
}