You are here

function _microdata_process_page in Microdata 7

Inserts the meta elements for items which have been added.

Handles data added by microdata_field_attach_view_alter() or by any custom layout systems like Views.

See also

microdata_field_attach_view_alter()

2 calls to _microdata_process_page()
microdata_process_page in ./microdata.module
Implements MODULE_process_HOOK().
microdata_process_panels_everywhere_page in ./microdata.module
Implements MODULE_process_HOOK().

File

./microdata.module, line 512

Code

function _microdata_process_page(&$variables) {
  $page =& $variables['page'];
  $items = microdata_item();
  $titles = array();
  $schema_urls = array();
  foreach ($items as $entity_type => &$ids) {
    foreach ($ids as $id => &$attributes) {
      $entity = entity_load_single($entity_type, $id);

      // Add the titles' itemprops. Because we can't be sure that the title
      // will be nested within the entity's HTML element, we use <meta> to
      // place a copy of the value.
      if (!empty($entity->microdata['title']) && !empty($entity->microdata['title']['#attributes'])) {

        // Sometimes the title is actually a 'name' property.
        $title = isset($entity->title) ? $entity->title : $entity->name;
        $field_id = microdata_get_itemref_id();
        $entity->microdata['title']['#attributes']['content'] = $title;
        $entity->microdata['title']['#attributes']['id'] = $field_id;
        $titles[$entity_type][] = array(
          '#attributes' => $entity->microdata['title']['#attributes'],
        );
        $attributes['#attributes']['itemref'][] = $field_id;
      }

      // Add the Schema.org URLs.
      // @todo Remove once Google recognizes itemids #1784580.
      if (!empty($entity->microdata['microdata_schema_url'])) {
        $field_id = microdata_get_itemref_id();
        $entity->microdata['microdata_schema_url']['#attributes']['id'] = $field_id;
        $schema_urls[$entity_type][] = array(
          '#attributes' => $entity->microdata['microdata_schema_url']['#attributes'],
        );
        $attributes['#attributes']['itemref'][] = $field_id;
      }
    }
  }

  // Add Schema.org URLs.
  // @todo Remove this when Google accepts itemid #1784580.
  $page['content']['microdata_items']['items'] = array(
    '#type' => 'markup',
    '#markup' => theme('microdata_item_meta_tags', array(
      'items' => $items,
      'html_tag' => 'span',
    )),
  );
  $page['content']['microdata_items']['titles'] = array(
    '#type' => 'markup',
    '#markup' => theme('microdata_item_meta_tags', array(
      'items' => $titles,
      'html_tag' => 'meta',
    )),
  );
  $page['content']['microdata_items']['schema_urls'] = array(
    '#type' => 'markup',
    '#markup' => theme('microdata_item_meta_tags', array(
      'items' => $schema_urls,
      'html_tag' => 'link',
    )),
  );
}