You are here

function _addressfield_render_address in Address Field 7

Related topics

1 call to _addressfield_render_address()
addressfield_render_address in ./addressfield.module
Render an address in a given format.

File

./addressfield.module, line 263
Defines a field for attaching country-specific addresses to entities.

Code

function _addressfield_render_address(&$format, $address) {
  foreach (element_children($format) as $key) {
    $child =& $format[$key];

    // Automatically expand elements that match one of the fields of the address
    // structure.
    if (in_array($key, array(
      'name_line',
      'first_name',
      'last_name',
      'organisation_name',
      'country',
      'administrative_area',
      'sub_administrative_area',
      'locality',
      'dependent_locality',
      'postal_code',
      'thoroughfare',
      'premise',
      'sub_premise',
    ), TRUE)) {
      if (isset($child['#render_type'])) {
        $child['#type'] = $child['#render_type'];
      }
      else {
        $child['#type'] = 'addressfield_container';
        if (!isset($child['#tag'])) {
          $child['#tag'] = 'span';
        }
      }

      // If the element instructs us to render the option value instead of the
      // raw address element value and its #options array has a matching key,
      // swap it out for the option value now.
      if (!empty($child['#render_option_value']) && isset($address[$key]) && isset($child['#options'][$address[$key]])) {
        $child['#children'] = check_plain($child['#options'][$address[$key]]);
      }
      elseif (isset($address[$key])) {
        $child['#children'] = check_plain($address[$key]);
      }
      else {
        $child['#children'] = '';
      }

      // Skip empty elements.
      if ((string) $child['#children'] === '') {
        $child['#access'] = FALSE;
      }

      // Add #field_prefix and #field_suffix to the prefixes and suffixes.
      if (isset($child['#field_prefix'])) {
        $child['#prefix'] = (isset($child['#prefix']) ? $child['#prefix'] : '') . $child['#field_prefix'];
      }
      if (isset($child['#field_suffix'])) {
        $child['#suffix'] = (isset($child['#suffix']) ? $child['#suffix'] : '') . $child['#field_suffix'];
      }
    }

    // Recurse through the child.
    _addressfield_render_address($child, $address);
  }
}