You are here

function _schemaorg_contrib_addressfield_add_attributes in Schema.org 7

Helper function to recursively inject RDFa attributes in an address item.

1 call to _schemaorg_contrib_addressfield_add_attributes()
schemaorg_contrib_field_preprocess_addressfield in modules/schemaorg_contrib/schemaorg_contrib.addressfield.inc
@file Addressfield field formatter specific code for schema.org.

File

modules/schemaorg_contrib/schemaorg_contrib.addressfield.inc, line 23
Addressfield field formatter specific code for schema.org.

Code

function _schemaorg_contrib_addressfield_add_attributes(&$address, $values) {

  // Define schema.org mappings which will be injected in the addressfield
  // formatter output.
  static $mappings = array(
    'thoroughfare' => 'schema:streetAddress',
    // 'premise' => // not defined on schema.org
    'postal_code' => 'schema:postalCode',
    'locality' => 'schema:addressLocality',
    'administrative_area' => 'schema:addressRegion',
    'country' => 'schema:addressCountry',
    'name_line' => 'schema:name',
  );
  foreach (element_children($address) as $key) {
    $child =& $address[$key];

    // Automatically add RDFa property attribute to each address element.
    if (in_array($key, array_keys($mappings), TRUE)) {
      $child['#attributes']['property'][] = $mappings[$key];

      // Use ISO country code as country value.
      if ($key == 'country' && $values['country']) {
        $child['#attributes']['content'] = $values['country'];
      }
    }

    // Recurse through the child.
    _schemaorg_contrib_addressfield_add_attributes($child, $values);
  }
}