You are here

function microdata_entity_property_info_alter in Microdata 7

Implements hook_entity_property_info_alter().

The microdata flag is set to TRUE on fields in the field_info hook. That isn't made available through the Entity Property API, so add it to the property info here.

Additionally, in order to enable microdata on field properties that are defined in core, we use the alter hook. If Entity API and microdata are pulled into core in Drupal 8, this would not be necessary.

File

./microdata.module, line 236

Code

function microdata_entity_property_info_alter(&$info) {
  $field_info_fields = field_info_fields();
  $field_types = field_info_field_types();

  // Go through all the fields on all the bundles.
  foreach ($info as $entity_type => &$entity_info) {
    if (isset($entity_info['bundles'])) {
      foreach ($entity_info['bundles'] as $bundle_name => &$bundle_info) {
        if (!empty($bundle_info['properties'])) {
          foreach ($bundle_info['properties'] as $field_name => &$field_info) {
            if (!empty($field_info_fields[$field_name]['type'])) {

              // Make a field's microdata status avaiable through the property API.
              $field_type = $field_info_fields[$field_name]['type'];
              if (!empty($field_types[$field_type]['microdata'])) {
                $field_info['microdata'] = TRUE;
              }
            }

            // If a bundle uses a text_formatted field, turn microdata on for the
            // value property and the summary property if there is one.
            if ($field_info['type'] == 'text_formatted') {
              $field_info['property info']['value']['microdata'] = TRUE;
              if (isset($field_info['property info']['summary'])) {
                $field_info['property info']['summary']['microdata'] = TRUE;
              }
            }
          }
        }
      }
    }
  }
}