Address fields are not displayed in views.

Query is OK, this is a theming problem.

If I select the default display, full address is displayed using the theme_addresses_cck_formatter_addresses function (see http://drupal.org/node/323961).

Selecting other display (city name, zip, country) display nothing, and no theme function is called.

Frederic

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

flebas’s picture

Title: CCK addresses fields not dosplayed in views » CCK addresses fields not displayed in views

I have changed addresses_cck_field_formatter_info function in file addresses_cck.module (see http://drupal.org/node/323961).

Views are working a bit better, default view (complete address) is now displayed regardless of selected address field.

I presume some complementary code should be implemented to handle views address fields. I can do the work if someone gives me some clues to start.

Frederic

Pancho’s picture

Version: 6.x-1.0-alpha2 » 6.x-1.0-alpha3
Priority: Normal » Critical

This bug is still open. I'd classify it as critical, as it renders the views implementation useless, except the admin patches the module or uses custom themeing. I need this for a project, so I might take a look at it the next days.

Pancho’s picture

Status: Active » Needs review
FileSize
9.99 KB

While Flebas' quick fix was tied to specifically named fields, here's a generic solution!
Enclosed patch adds full views support for displaying single CCK fields and 'single line address' and some code and UI improvements.

smoothdzion’s picture

Does anyone elses patch crap out on addresses_cck/addresses_cck.module? Pancho I appreciate the patch but it keeps dying on me.

AntiNSA’s picture

Hi! I am trying to create an online learning thing and I want to give users the chance to create a content type, and chose the country and city for the content type they create, and then I create a list in views of the node title, city, and country in a table mode grouped by country.

I tried using addresses but every thing I do it says that it cant locate the provence and I should entry the country code. Way to hard for me and my students....

In the views I was able to add the field so it says country, city, contenent.... and even created a content type and added the fields to the content type....

I even went into the folder and cound the code for the city I live in in China and put the code in. I added the code to views and sadly it does not show the information . Only the node title and the titles for city country and continent, but bit the name. I cant create taxonomy for every city and country in the world, I cant ask my users for each and every code....

Is there some way to do this that doesnt kill me ? I thought addresses was it but I guess you have to be a sql genius hacker... I try my best...

Thank you for your help if you have any ideas

AntiNSA’s picture

And does this patch work or not? I need to get this going, but I dont want to apply the patch if it is unknown to be ok.... that would make troubleshooting more difficult

AntiNSA’s picture

I believe it is meant to be patched to the addresses_cck.inc file not the .module file

AntiNSA’s picture

OK after playing with this for a while I realized that you made this patch for the non-released head version. The newest version for download is the alpha 3 version. I would like to use the head version, and have had no luck after looking for a couple of hours through the forum on how to download the head version. I need to be able to display the city only, and the country only, using cck/views and allow them to be sortable. I tried flebas and it displayed the city and the country together.... I believe your trying to do the same thing I am. I looked at you patch, dont know much about patching, used to used cyg win to patch files.
In you patch you patch multiple files, and I have only used cyg to patch a single file at a time..

So I looked at the patch which you made and sam that it is for a newer version than what is up to download. Can you please give me info on how to download the newest head version?

All I could find were the individual files at http://cvs.drupal.org and not a rar to download.This is a pretty important thing for me and I would be happy for the help.

I cant try your patch if I cant get the same head version you have to patch it.....

AntiNSA’s picture

Ok , I downloaded the cvs of each file you had in the patch, one by one through copy and paste, made the changes, and completely lost the progress that was made on the other installation with fleba. Hours to learn what doesnt work.

Perhaps ts because I had only the pieces of the head version which you patched. It would be nice if the head version was available to download on the project page.

Now I will install it again with flebas mod.

Desperatly awaiting the ability to use this with views correctly....

dotist’s picture

subscribing

jantoine’s picture

Version: 6.x-1.0-alpha3 » 6.x-1.x-dev
FileSize
11.01 KB

I have taken the patch from #3 and updated it against HEAD, thus I am changing the version to 6.x-1.x-dev. I have also included additional fixes not in the patch from #3.

The patch removes all of the duplicate fields in the views selection list replacing it with one Addresses field. This Addresses field has many formatters that allows you to get the output you wish desire whether it be the complete address (default) or a single address field. To get multiple single fields, add the Addresses field to a view multiple times choosing the correct formatter for the desired field.

If you test this patch, please provide feedback. We get nowhere without tester feedback.

Cheers,

Antoine

bekasu’s picture

This is a cross post from my result on applying the state patch and the cck patch:

I applied the state patch for the state option and for the cck patch.

When I run the update after applying both patches, I get the following error:

user warning: Table 'vitaesha_drp01.variable' doesn't exist query: DELETE FROM variable WHERE name LIKE 'addresses_format_%' in C:\www\drupal-6.13\sites\all\modules\addresses\addresses.install on line 30.

This is the query that failed:

addresses module
Update #6106

    * Failed: DELETE FROM variable WHERE name LIKE 'addresses_format_%'

Neither the state drop down box appears nor are the variables available to CCK.
I'll cross post in the CCK issue.

bekasu’s picture

Took this in smaller steps.

1. downloaded head for addresses
2. applied cck patch
3. moved code to localhost directory
4. checked to see if update.php needed to be run, it did not
5. created a view
6. no addresses field was available for selection as a views field
7. checked addresses admin settings - everything looked okay
8. checked drupal permissions - addresses permissions were both checked
9. ran this check with the admin ID

Environment was same as before: WAMP, Apached 2.2.11, Php 5.2.9-2, Mysql 5.1.33, Drupal 6.13

codycraven’s picture

Status: Needs review » Needs work
FileSize
9.41 KB

I have re-rolled this patch as it does not apply to the current version of HEAD. There were multiple changes to addresses_addressesfieldapi() that I left out (periods at the end of translated items) as I want to focus on the functionality of the patch first.

There are a lot of items to look at in this patch that are not functioning as I would hope/expect. The largest that I have noticed is that in Views you are no longer able to select individual elements of the address to Filter on or supply as an Argument. This may be due to some unintended modifications that this re-rolled patch has made against the current HEAD version.

Please review and if this patch is functioning as it did when first released then let me know so that we may work on the Arguments and Filters next.

alienatix’s picture

subscribing

codycraven’s picture

I am working on a new issue to make major changes to the formatting system - see #680354: Unify hCard/plain formats to singular format. If this patch is not fixed prior to that issue being committed then this patch will need to be updated to work with the new system.

abaddon’s picture

i can confirm this patch works against the latest stable but it didnt added what i needed, a single city field
it really needs some work to just allow single fields, its not much work, i might do it if i get time to properly review it
i think it shouldnt be applied to the stable release as it is, if it breaks stuff, it really doesnt add much

codycraven’s picture

abaddon,

#680354: Unify hCard/plain formats to singular format has been moved to 2.x so there is no need to worry about breaking anything if you are working against the latest stable release.

If you do end up working on this please work against dev, as dev 1.x is stable and will remain stable.

frob’s picture

subscribing.

AlexisWilke’s picture

codycraven,

Could we have access to 2.x then?

At this point, I cannot display a US address properly without making changes to the code. And 2.x does not appear in the Issue Version drop down.

Thank you.
Alexis

jargylplath’s picture

Hello. Any updates on this?

The patch in #14 is many versions old, but I went through manually and applied the changes to the relevant files against 6.x-1.10. This mostly worked as Cody described. In the fields section of Views it did reduce the duplicate (but not really duplicate) entries to a single entry. However, it did not add single field formats to the field.

Also, as you detail in your comment above, it did remove the ability to select specific elements in Filters. However, in version 6.x-1.10 these individual filters don't work in the first place. They all filter against "_is_primary".

So, I was able to get around the single fields problem by using the module Views Formatted Fields. I add the full default address as an Excluded field, then add a Virtual Formatted Field that pulls a token from the excluded addresses field.

However, the filter thing is still an issue. Even when I roll back to pre-your patch and have the ability to add the individual filters I want, because they filter against "_is_primary" they don't work. Any suggestions on what to tweak in the code to correct this?

Ideally the filters for Country and Province would also be dropdowns rather than text boxes, but I realize that that is a separate request than fixing this bug.

Thanks for your help, I'd love to see this move forward and get pushed out. I'm happy to help with developing the fix, but I need a point in the right direction.

jargylplath’s picture

OK. I seemed to have fixed the "_is_primary" problem as described in my post above. The problem was that in the addresses_cck_field_settings() method a line was missing that defined the field in the filter array. I'm attaching a patch that details that change. This patch is assuming that Cody's patch has not been installed and so the individual fields show up in the filters area.

(this is my first time preparing a patch file... I think I followed the tutorial correctly, but my apologies in advance if I did something wrong.)

[EDIT: I noticed after this posted that my spacing conventions in the last added line around my concat operations are different than the module's. I would correct this, but it doesn't seem like I can edit the attachment and it seems silly to add it a second time for merely that purpose.]

jargylplath’s picture

OK. Sorry for the flurry of posts, but I've traced the problem with filter options vanishing to the following lines of code in addresses_cck/addresses_cck.module. In Cody's patch, lines 158–187 are dropped. Something in here reduces the duplicate (not 100% duplicate) options in the fields area of Views, but this is where those filter options are set. (NOTE: These lines include my patch [lines 176–181] that fixes the filters not working.)


119 function addresses_cck_field_settings($op, $field) {
120   switch ($op) {

158     case 'views data':
159       // Rerebuild the Views integration, since the address field is,
160       // in fact, a bundle of fields.
161       $db_info      = content_database_info($field);
162       $table_alias  = content_views_tablename($field);
163       $cck_default  = content_views_field_views_data($field);
164       $data[$table_alias]['table'] = $cck_default[$table_alias]['table'];
165       unset($cck_default[$table_alias]['table']);
166 
167       $cck_default = array_shift($cck_default[$table_alias]);
168 
169       $ftypes = module_invoke_all('addressesfieldapi', 'fields');
170       foreach ($ftypes as $ftype => $field_data) {
171         $field_cck = $cck_default;
172         if (isset($field_data['title'])) {
173           $field_cck['title'] .= ' '. $field_data['title'];
174         }
175         $field_cck['field']['field'] = $field['field_name'] .'_'. $ftype;
176 
177         // Adding in the field to the filter array
178         $field_cck['filter']['field'] = $field['field_name'] .'_'. $ftype;
179 
180         // Tweaked to include the short title to distinguish multiple addresses in the same node when picking filters.
181         $field_cck['filter']['title'] = $cck_default['title short'] .': '. $field_cck['filter']['title'] .' '. $field_data['title'];
182 
183 //         unset($field_cck['field']['additional fields']);
184         $data[$table_alias][$field['field_name'] .'_'. $ftype] = $field_cck;
185       }
186                                                                                                                                                                                                     
187       return $data;
188   }
189 }

Thoughts?

AlexisWilke’s picture

Your patch looks good and I checked in the fix especially the 'field' instead of 'filter' entry!

Was your patch against the HEAD? That would be most useful rather than a patch after another that doesn't apply as is anymore... 8-)

If you could check again after the new -dev appeared (it takes about 12h to update.)

Thank you.
Alexis

AlexisWilke’s picture

Do we need line 175 and 178?

In #22 your patch removed line 175...

Thank you.
Alexis

jargylplath’s picture

Well, you *do* need 175 (they are used by different sections of the code). However, I think I fixed, or at least took a major leap forward to solving the other problems with Cody's patch. I'm developing off of 1.10, so I'll take a look at the head and compare against this new revision of Cody's patch before I post it here. And *that* patch *does* alter 175 because it is part of the redundancy.

Could I *stress* more *words*?

_*Probably*_

^_^

jargylplath’s picture

FileSize
9.24 KB

OK. Here is the revision of Cody's patch from #14. This is off of HEAD. (When I pulled it down it had the changes already.)

I would think that this is not the final solution. This should likely be treated as a stepping stone or as a method of exploring the problem.

This does seemingly address the filters situation (by using the fix from above). However, (and this is flagged with a comment) I am forcing all the filters to be a string comparison. Previously it was forcing them to be integer comparisons which would only work on integer and boolean fields. This should probably be determined dynamically based on each table field definition.

It also addresses the situation of single fields not showing up under Fields in Views. Now they all show up. However, (and I marked this in the code with comments) for those single fields I only really implemented a full fix for plain outputs. What I mean is that plain fields will be marked-up and returned appropriately, but I don't know that hcard stuff will work.

Also, rather than dropping the switch case that builds the information for Views (as Cody did) I left it (for filters to work). So to remove all the duplicates in Fields I just unset all but the first one. This is probably also not the best approach and is marked by comments in the code.

dkinzer’s picture

Hi, as mentioned in my comment @ #359859-30: Views integration of user addresses I needed to be able to create a views using individual fields from the compound Addresses field and then also be able to sort by that field. Sadly it looks like it was not possible. But I created a very simple patch that helps me accomplish what I need and is backward compatible with other adresses_cck views.

In order to apply one of these fields I use the following steps.

1. First I find and add the field of interest.

2. Next I add a php custom field who's output is $data->{field of interest}.

3. Finally I go back to step one and rewrite output to output of step 2.

This way I can create a views table with a column of phone numbers (for example) and be able to sort the table by the phone numbers or what have you.

attached is the patch that helps gives this feature. You will need to disable and then re-enable the addresses module so that the cached 'database columns' for the cck field settings can be reassigned with the sortable attribute.

I see that by the efforts applied so far steps two and three would not be necessary, but being able to sort these fields in a Views table is a necessity in my opinion.

dkinzer’s picture

There seems to be a mistake in the patch for comment #324331-27: CCK addresses fields not displayed in views:

-function theme_addresses_cck_formatter_single_line($element) {
+function theme_addresses_cck_formatter_singleline($element) {

the function name is being changed but the formatter callback is still ... formatter_single_line.

anil614sagar’s picture

Its good to convert text field to select list in views exposed filters. Any idea how to do this..?

dkinzer’s picture

I just redid patch 28 against origin/master in new git system.

dkinzer’s picture

There was in error in the patch on 31 so I'm resubmitting here.

dkinzer’s picture

Status: Needs work » Needs review
Tarch’s picture

FileSize
8.48 KB

Hi,
in patch at #27 there was a little omission, the line:

module_load_include('inc', 'addresses');

was missing in function

function theme_addresses_cck_formatter_field($element) {
   ...
}

I attach the patch that adds the incriminated line.

webadpro’s picture

I'm just wondering how is this coming along?

I'm trying to expose the country field but I'm getting a regular textfield rather than the select field.

Any help or update would be great.

nevets’s picture

Here is an alternative to theme_addresses_cck_formatter_field() that handles all the fields and formats

function theme_addresses_cck_formatter_field($element) {
	$parts = explode('_', $element['#formatter']);
	$format = array_pop($parts);
	$field = implode('_', $parts);
	
  // Include the important .inc file
  module_load_include('inc', 'addresses');

  // Print the address
  return theme('addresses_' . $field, $element['#item'], $format);
}
AlexisWilke’s picture

nevets,

Interesting. From what I can see, we don't currently have such a formatter for the fields. Is that correct?

I only see two functions: theme_addresses_cck_formatter_default() and theme_addresses_cck_formatter_single_line().

Thank you.
Alexis

nevets’s picture

The pathes use that function to handle the theming of the individual address elements

rayvan’s picture

If you just want exposed filters to work. Use the patch located here:
http://drupal.org/node/793790#comment-6603042

bkat’s picture

What branch and what patches do I need so that I can create views field that displays one of the components of an address?

Anonymous’s picture

Anyone still using D6 Addresses that needs to have City, Country, and Province in Views can add it in doing this:

add these functions to addresses/addresses_cck/addresses_cck.inc:

function theme_addresses_cck_formatter_country($element) {
  module_load_include('inc', 'addresses');
  return theme('addresses_country', $element['#item'], 'name');
}

function theme_addresses_cck_formatter_province($element) {
  module_load_include('inc', 'addresses');
  return theme('addresses_province', $element['#item'], 'name');
}

function theme_addresses_cck_formatter_city($element) {
  module_load_include('inc', 'addresses');
  return theme('addresses_city', $element['#item'], 'plain');
}

find the function addresses_cck_field_formatter_info() and make it look like this in addresses/addresses_cck/addresses_cck.module (I added Province, City, Country formatters for Views):

function addresses_cck_field_formatter_info() {
  $default = array(
    'arguments'       => array('element'),
    'multiple values' => CONTENT_HANDLE_CORE,
    'field types'     => array('addresses_cck'),
  );
  $formatters = array(
    'default' => array(
      'label'           => t('Default'),
      'arguments'       => array('element'),
      'multiple values' => CONTENT_HANDLE_CORE,
      'field types'     => array('addresses_cck'),
    ),
    'single_line' => array(
      'label'           => t('Single Line'),
      'arguments'       => array('element'),
      'multiple values' => CONTENT_HANDLE_CORE,
      'field types'     => array('addresses_cck'),
    ),
    'country' => array(
      'label'           => t('Country'),
      'arguments'       => array('element'),
      'multiple values' => CONTENT_HANDLE_CORE,
      'field types'     => array('addresses_cck'),
    ),
    'city' => array(
      'label'           => t('City'),
      'arguments'       => array('element'),
      'multiple values' => CONTENT_HANDLE_CORE,
      'field types'     => array('addresses_cck'),
    ),
    'province' => array(
      'label'           => t('Province'),
      'arguments'       => array('element'),
      'multiple values' => CONTENT_HANDLE_CORE,
      'field types'     => array('addresses_cck'),
    ),
  );

/*
  $afields = module_invoke_all('addressesfieldapi', 'fields');
  foreach ($afields as $ftype => $field) {
    if (!empty($field['theme'])) {
      foreach ($field['theme'] as $theme => $description) {
        $formatters['addresses_field_'. $theme] = $default;
        $formatters['addresses_field_'. $theme]['label'] = $description;
      }
    }
  }
*/
  return $formatters;
}

I commented out that last block of code because it was adding formatters to Views that don't work. It quite honestly pissed me off to no end until I figured out where it was coming from.

In the same file, find the addresses_cck_theme() function and make it look like this (adding City, Country, Province theme info):

function addresses_cck_theme() {
  return array(
    // Shows address in the default view: Multilines
    'addresses_cck_formatter_default' => array(
      'arguments' => array('element'),
      'file'      => 'addresses_cck.inc',
    ),
    // Shows address in only one line
    'addresses_cck_formatter_single_line' => array(
      'arguments' => array('element'),
      'file'      => 'addresses_cck.inc',
    ),
    'addresses_cck_formatter_country' => array(
      'arguments' => array('element'),
      'file'      => 'addresses_cck.inc',
    ),
    'addresses_cck_formatter_city' => array(
      'arguments' => array('element'),
      'file'      => 'addresses_cck.inc',
    ),
    'addresses_cck_formatter_province' => array(
      'arguments' => array('element'),
      'file'      => 'addresses_cck.inc',
    ),
  );
}

This works pretty well! The City, Province, and Country formatters show up if you are trying to show an address in views now with those bits individually. However, we can't sort or click sort by these. Why? Because this module rebuilds the views data call... Let's fix that by adding the sort handlers back in.

In addresses/addresses_cck/addresses_cck.module find the function addresses_cck_field_settings(). In the 'views data' case statement, add the following AFTER '$field_cck['filter']['title'] .= ' '. $field_data['title'];':

$field_cck['sort']['handler'] = 'views_handler_sort';
$field_cck['field']['click sortable'] = TRUE;

This will let table fields be click sortable and also allow you to sort by those address fields.