If you have multiple addresses enabled for a content type, and create a view to display these addresses, it will only display the first address. I think it calls "location_views_field_handler_address", which only runs through the theme_location code.

Is there a way to display multiple addresses in a view if they exist?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

catch’s picture

Version: 5.x-2.7 » 6.x-3.x-dev

Still valid in 3.x - using either an individual field or the 'address' field.

YesCT’s picture

Status: Active » Postponed (maintainer needs more info)

Not ideal, but I wonder if you used contemplate, or a template file, if you used a for loop on the array, you could force all the addresses to print out?

There have been a lot of updates since July 2008, could someone, or the original poster try this again with the latest version please. I'll mark it as postponed, needs more info, for now.

YesCT’s picture

tagging

YesCT’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

No reply, so marking closed. Please change status to active and add more info if this is still a problem for you.

Offlein’s picture

This is still an issue. Views "Location: Address" outputs the first address, no others, no options.

Offlein’s picture

Status: Closed (fixed) » Active

I forgot to reopen the issue..

YesCT’s picture

Status: Active » Postponed (maintainer needs more info)

I know this has been draggin on a while, but there were a lot of changes in the new official release, Please check to see if this is still a problem in the new release. If it is, reply with a new summary and set the status back to active.

jason.lally@gmail.com’s picture

This is still a problem in the new release as well as the dev release. It will only display the first address entered in a list of multiple addresses. Any ideas on where to start looking? Is this a views problem or a location problem?

jason.lally@gmail.com’s picture

When I run the views created query manually, I do get three locations back from the database. Where does views/location control the looping through these items? I'm just getting into views, what hook/handler controls the output of views?

jason.lally@gmail.com’s picture

Status: Postponed (maintainer needs more info) » Active
jason.lally@gmail.com’s picture

Okay,

Here's what I think I've found. I played with the output of the address handler (location/handlers/location_handler_field_location_address.inc). The render function looks like this:

function render($values) {
    if ($values->{$this->field_alias}) {
      $location = location_load_location($values->{$this->field_alias});
      if ($location['lid']) {
        return theme('location', $location, $this->options['hide']);
      }
    }
  }

When I played with outputting the content of $values->{$this->field_alias}, I get a single ID. That ID corresponds with the first lid returned by the query. I've been poking around at other analogous modules that output multiple values and can't quite figure out where the right place is to intercede. I thought views intelligently understood when multiple values were returned from a query and would render them "automatically."

Any ideas?

jason.lally@gmail.com’s picture

Another update: It seems that it will display multiple locations but it only allows you to break them out into separate rows and not group them into one row as multiple fields. This may not be a bug so much as a feature request.

If I have multiple values stored in a CCK text field, for instance, I have the option to group these. The same should probably exist for locations.

For example. I want a single block that can group multiple locations that would show up in an At A Glance type block on a page, taking the NID as an argument to display this information. There are ways around this, but they are all a bit hackish.

mr_scumbag’s picture

You say "Another update: It seems that it will display multiple locations but it only allows you to break them out into separate rows and not group them into one row as multiple fields"

How do you display the multiple locations ?
I cannot get it to output any location other than the first.
Separate rows would be fine for me, but only the first lid gets diplayed.
How did you get it to display multiple locations for a single node in views ? (Without views producing duplicate node entries with only the address different)

I'm using Location in CCK

rooby’s picture

rooby’s picture

Title: Views Location: Address only displays first address » Add a "group multiple values" option for location fields in views (like CCK multiple value fields)
Category: bug » feature

A full description of the issue:

The "group multiple values" option that CCK provides for its multiple value fields is the kind of functionality we want.
If you use the "Content: Location" field in your view you can use the cck "group multiple values" setting and it will work. Note that this field didn't work properly until a patch was committed a couple of days ago so you will have to use the latest dev version.

However, if you use the views fields provided by the location module, such as those used for node locations, user locations and cck locations via a relationship to the location, it won't work. Because the location module doesn't support it yet.
That functionality will have to be added.

We need to keep the existing functionality as is (a separate row for each location entry) and add an option to "group multiple values" like CCK does. This was we don't break any existing sites.

If someone wants to make a patch you could use the cck code as a starting point.
The code is in the cck module in includes/views/handlers/content_handler_field_multiple.inc

rooby’s picture

Component: Code » Location_views
ShaneOnABike’s picture

+1 subscribe I'd definitely like this functionality

naught101’s picture

Exactly as #15 describes. This is going to hit me hard soon, so I'll try to have a look at it. No promises.

naught101’s picture

Hrm. As described in #15 , "Content: location" works, and that's good enough for my purposes, so I won't be working on this.

Scratch that. I can use "Content: Location" for one field, but I need "Location: Province" for another, since the "Content: Location" field can't be split in to individual field value components, as far as I can tell..

Clarification:
My set up: "Group" content type, with 3 different Location fields:
1) "Location" - physical home address of the group. Cardinality: 1
2) "Postal address" - as stated. Cardinality: 1
3) "Covered postcodes" - postcodes of all the areas in which the Groups work. Cardinality: unlimited.

What I want:
A table, with one row per group, listing:
- group name
- Province from "Location"
- all postcodes from "Covered Postcodes" united into one table cell.

I'm using "Content: Covered Postcodes" with a field re-write to combine multiple post codes successfully.

I have to use "Location: Province" because with "Content: Location" I can't get the province alone. It is THIS field that's causing the row duplication: the "Location: Province" appears to be trying to get the (empty) province sub-field from the "Covered Postcodes" and "Postal address" fields. I could get around this if I could use Distinct(nid), but #863478: Distinct is not supported by dbtng, so I think this has to be dealt with in location.

rooby’s picture

Re #19:
Yeah, only the field provided by cck will do the multi value thing, but then you get the whole location, not just a part of it like the state.
So to group some and not others you would have to do some custom themeing for your view so that you get multiple post codes but not multiple provinces.
At least until this issue is resolved.

ShaneOnABike’s picture

ping - any progress I don't really know how to set this up myself or I would attempt to write the code :/

ShaneOnABike’s picture

Status: Active » Needs review
Issue tags: +CCK, +group by
FileSize
1.82 KB

Alright well I have created the first patch to work with the Location: Country views handler, which was the problem that I was having for my site.

Note: I realize that this patch isn't applicable to *all* the different handlers but I wanted to start with one and the get the maintainers to check it out first before I go and deploy this on all the various handlers.

It took me a while to figure out all the handler code but after studying a few different ones I think I've got it. So basically it provides the option to output as a few different options (which can be overwritten theme wise I believe).

So feedback would be awesome and testing!!

Note: This only works (for now) with the Handler for the field not filters, argument, etc.

ShaneOnABike’s picture

Okay actually I changed this a bit more and added provinces to be output as well.

I had coded it to create an array with the results being in 'item' but I prefer to use the aliases already setup since I think that makes more sense. So here's the fix for country and province fields (this time using git properly)

ShaneOnABike’s picture

Category: feature » bug
FileSize
24.96 KB

Here is the full complete integration I just need someone to test this out to make sure it works properly :)

ShaneOnABike’s picture

Status: Needs review » Patch (to be ported)
gjmokcb’s picture

Not quite there. My view stores city, province, country. Hides the first two, then re-writes the third to include all three values. So the result of city: Kansas City, province: Missouri, country: United States is "Kansas City, Missouri, United States." With this patch installed and a second location added (Chicago), the result is:

Chicago,Kansas City, Illinois, United States; Chicago,Kansas City, Missouri, United States

Not separating the cities.

gjmokcb’s picture

Oooog. And the view is displaying two identical instances. If I set "items to display" to 1, then it displays only one instance with only one city. So it's not grouping, and it's incorrectly displaying multiple cities.

gjmokcb’s picture

And I'm sorry to say that when you don't want to group values, just list (for example) people with their home town, line-by-line, the patch puts everyone's city on every line. So I've de-patched.

podarok’s picture

Status: Patch (to be ported) » Needs review

bot?

podarok’s picture

Category: bug » feature
Status: Needs review » Needs work
Issue tags: -CCK, -location multiple locations, -group by +Needs tests, +Needs manual testing
+++ b/handlers/location_handler_field_location_city.incundefined
@@ -0,0 +1,47 @@
+       $this->items[$value->nid][$field] = array(
+	$this->field_alias => $field, ¶
+       );
+++ b/handlers/location_handler_field_location_country.incundefined
@@ -23,12 +23,41 @@ class location_handler_field_location_country extends views_handler_field {
+     }
   }
+ ¶
+++ b/handlers/location_handler_field_location_country.incundefined
@@ -23,12 +23,41 @@ class location_handler_field_location_country extends views_handler_field {
+   }
+ ¶
+++ b/handlers/location_handler_field_location_country.incundefined
@@ -23,12 +23,41 @@ class location_handler_field_location_country extends views_handler_field {
+   */
+   function render_item($count, $item) {  ¶
+++ b/handlers/location_handler_field_location_lid.incundefined
@@ -0,0 +1,47 @@
+       $this->items[$value->nid][$field] = array(
+	$this->field_alias => $field, ¶
+++ b/handlers/location_handler_field_location_name.incundefined
@@ -0,0 +1,47 @@
+       $this->items[$value->nid][$field] = array(
+	$this->field_alias => $field, ¶
+++ b/handlers/location_handler_field_location_postal.incundefined
@@ -0,0 +1,47 @@
+       $this->items[$value->nid][$field] = array(
+	$this->field_alias => $field, ¶
+++ b/handlers/location_handler_field_location_province.incundefined
@@ -30,12 +30,41 @@ class location_handler_field_location_province extends views_handler_field {
+       $this->items[$value->nid][$field] = array(
+	$this->field_alias => $field, ¶
+	$this->aliases['country'] => $country);
+++ b/handlers/location_handler_field_location_province.incundefined
@@ -30,12 +30,41 @@ class location_handler_field_location_province extends views_handler_field {
+    if ($this->options['style'] == 'name') { ¶
+      $countryalias = $this->aliases['country'];
+      return check_plain(location_province_name($item[$countryalias], $item[$this->field_alias]));
+++ b/handlers/location_views_handler_field_coordinates.incundefined
@@ -12,13 +12,42 @@ class location_views_handler_field_coordinates extends location_views_handler_fi
   }
-
+  ¶
+++ b/location.views.incundefined
@@ -23,8 +23,11 @@ function location_views_handlers() {
+      'location_handler_field_location_lid' => array(
+	'parent' => 'views_handler_field_prerender_list',

Multiple tabstops and trailing whitspaces errors should be fixed before RTBC
Also this needs manual testing and testing coverage

podarok’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev

And main trouble - this is feature request, not a bug, so before 6.x it shoud be filled and comited against latest 7.x-3.x-dev

podarok’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests, -Needs manual testing

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs manual testing

The last submitted patch, location-views_handlers_complete-213792-24.patch, failed testing.

ShaneOnABike’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Issue tags: +CCK, +group by, +multiple locations

Hmm... not sure how to strip all those characters out. Seems when you tried to resubmit the patch doing so against 7.x is obviously going to fail.

Also for other folks testing this stuff I forgot that I also applied #752268: Print field-item wrappers for multi select lists even when only one item is selected. to make this work. I'm sorry for not mentioning that before. I think it makes a difference.

ShaneOnABike’s picture

@gjmokcb: feel free to modify the code :) I set this up to work with just outputting singular items not the entire item (so if you just wanted cities not the entire location it should work from what I recall)

I'm not sure why this hunk would fail if there are spaces instead of tabs but I removed all that and resubmitting. Maybe the way this is being created isn't correct? With reference to modifying multiple files...

ShaneOnABike’s picture

Status: Needs work » Needs review
podarok’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs manual testing

The last submitted patch, location-views_handlers_complete-213792-35.patch, failed testing.

skyredwang’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev

The patch needs to go against 7.x-3.x-dev

skyredwang’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests, -Needs manual testing

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs manual testing

The last submitted patch, location-views_handlers_complete-213792-35.patch, failed testing.

skyredwang’s picture

Status: Needs work » Needs review
FileSize
2.49 KB

I just made a smaller patch to test "group multiple values" for COUNTRY

skyredwang’s picture

Status: Needs review » Needs work

The above patch only has ability to combine mulitple values but still cause the duplicates. It's not a real "group multiple values" option

Pepper’s picture

Issue summary: View changes

The Views_distinct module takes care of getting rid of duplicates when I filter on node title.
However, this thread is 8 months old. I tried applying the patch to the current dev version but it failed, so I did it manually.

It seems to be working but I'm getting this error:
Strict warning: Declaration of location_handler_field_location_country::pre_render() should be compatible with that of views_handler_field::pre_render() in require_once() (line 9 of path\location\handlers\location_handler_field_location_country.inc).

Ideas on fix?

Pepper’s picture

Another problem. This works, however, what if you want to list all the countries associated with a node, and link them _separately_ to something, oh, say a google map link.

Pepper’s picture

Okay, the patch has a small bug which is causing the error:
pre_render($values) should be pre_render(&$values).