Hi!

After succesfully used of this module in conjunction with Location module (see: http://drupal.org/node/1542404), I am experimenting now integration with Addressfield module (that's assuming more and more importance, and the version 7.x-5.x of Location module itself most likely will be based on it - see: http://drupal.org/node/1346746).

So, I've created a view that retrieve all Countries with at last a node associated to (see it in attachment).

Then I've setted up a Global Filter to use this Views.

Results:

The resulting select show problem very similar to issue in http://drupal.org/node/1542404:

<select id="edit-view-global-filter-addressfield" class="global_filter_2-view_global_filter_addressfield form-select" name="view_global_filter_addressfield">
  <option value="">Worldwide</option>
  <option selected="selected" value="46">AL</option>
  <option value="50">US</option>
</select>

But, we have here different problem:

  1. Options shows country CODE instead of country NAME
  2. Values in options are the NIDS of nodes associated to countries (instead they would be country CODES)
  3. Other countries associated to a single node (addressfield setted up to multivalue) are omitted (e.g. my view correctly retrieve also the country US for the same node that also have IT)

What I really don't understand is this mismatch of what Views returns with what the select provided by Global Filter shows: why Global Filter retrieve NIDS when my view doesn't return those? And why some records are missed when Views returns that instead?

Thank you very much.

CommentFileSizeAuthor
exported-views.txt5.44 KBMXT
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

RdeBoer’s picture

Sorry MXT,
Is this still an issue for you? Or did you find an alternative solution?
Rik

MXT’s picture

Hi!

unfortunately this is still an issue...

danon1981’s picture

Subscribing

MXT’s picture

YES, I have a working solution now.

I think all problems here are due to what amarcus explains here: http://drupal.org/node/1678596#comment-6226254

So, to resolve, I've used the addressfield_tokens module and developed a workaround similar to what I've already used here: http://drupal.org/node/1542404#comment-6046606

Addressfield_token provides a function _addressfield_tokens_country() very similar to location_country_name() provided by location module.

Here what I did:

In the view that retrieves all countries list I opted to use addressfield_token formatters/tokens, an turn on aggregation settings to group by country. In this way I obtain a select that shows wrong html, but correct data (resolving issue I've described in point 3 in my first post in this thread):

<select name="view_global_filter_addressfield" id="edit-view-global-filter-addressfield--2" class="global_filter_2-view_global_filter_addressfield form-select">
  <option selected="selected" value="">Worldwide</option>
  <option value="46">AL</option>
  <option value="47">IT</option>
  <option value="50">US</option>
</select>

So now I can do a form_alter to manipulate and rebuild the select in this way:

function helper_form_alter(&$form, $form_state, $form_id) {

  switch ($form_id) {
    case 'global_filter_2':
      $modified_options = array();
      foreach ($form['view_global_filter_addressfield']['#options'] as $option) {
        if ($option == 'Worldwide') {
          // manage exception for first value 'All' (worldwide in my case)
          $modified_options[''] = $option;
        }
        else {
          $modified_options[$option] = _addressfield_tokens_country($option);
        }
      }
      // Assign the new modified options:
      $form['view_global_filter_addressfield']['#options'] = $modified_options;
      break;

  }
}

And all works fine now!

Yes, this is still a workaround, so I hope this module can better manage addressfield data someday...

Thank you very much!!!

RdeBoer’s picture

Assigned: Unassigned » RdeBoer

No thank you MXT!
Your code will make a generic Addressfield integration easier. Great job.
I want to work on the integration, but don't have the time right now.
Rik

ceaucari’s picture

If i got it wright I think you could use http://drupal.org/project/location_taxonomize to automatically generate taxonomy terms from Address fields and this terms can be used with global filters
I hope it helps.

MXT’s picture

Thank you for your suggestion ceaucari but we already know about location_taxonomize (see my comment here: http://drupal.org/node/1542404#comment-6039412).

What we are trying to do here has another purpose.

RdeBoer’s picture

Status: Active » Postponed

Not so easy to create a generic solution for this.
For people wanting to do something like this with AddressField I suggest following along the lines of what MXT did in #4.
Rik

RdeBoer’s picture

Status: Postponed » Closed (won't fix)

Closing as no further expressions of interest and MXT provided a solution in #4.