From e76b0ee474b44d8c1df906d270e805997c289f19 Wed, 22 May 2013 00:09:23 +0200
From: hass <hass@85918.no-reply.drupal.org>
Date: Wed, 22 May 2013 00:08:51 +0200
Subject: [PATCH] Issue #991834: Address component Views support

diff --git a/views/addressfield.views.inc b/views/addressfield.views.inc
index 77a5b45..421bff1 100644
--- a/views/addressfield.views.inc
+++ b/views/addressfield.views.inc
@@ -22,5 +22,40 @@
     }
   }
 
+  // Add a field definition/handler for each address component.
+  $properties = addressfield_data_property_info();
+  foreach ($data as &$table) {
+    if (isset($table[$field['field_name']]['field']) && $field_def = $table[$field['field_name']]['field']) {
+      foreach ($table as $column_name => &$column) {
+        // Skip unused 'sub_premise' and useless 'data' fields.
+        if (empty($column['field']) && !in_array($column_name, array('field_address_sub_premise', 'field_address_data'))) {
+
+          $column['field'] = $field_def;
+          $column['field']['handler'] = 'views_handler_field';
+          $column['field']['real field'] = $column_name;
+          $column['field']['additional fields'] = array(
+            'delta',
+            'language',
+            'bundle',
+          );
+
+          // Insert xNAL label from the address field data structure
+          // so users can distinguish them in listings (compared to the default
+          // behavior, which only shows the xNAL key).
+          $field_labels = field_views_field_label($field['field_name']);
+          $field_label = array_shift($field_labels);
+          $property = str_replace($field_def['field_name'] . '_', '', $column_name);
+          if (!empty($properties[$property])) {
+            $property_label = $properties[$property]['label'];
+            $title = t('@field-label - @property-label', array('@field-label' => $field_label, '@property-label' => $property_label));
+            $column['title'] = $title;
+            $column['title short'] = $title;
+          }
+
+        }
+      }
+    }
+  }
+
   return $data;
 }
