Hi
I see a lot of issues in the queue along the lines 'there is a new province in country xx, please update your module' etc, it would be nice if location module gave other modules a chance to change the province values/lists as this would alleviate the need for you guys to patch the module for every change to provinces etc around the world.
I propose that location_get_provinces exposes a hook 'hook_location_provinces_alter' allowing other modules to alter the provinces before they hit the cache.
Also this would allow other modules to extend the location entry widget - eg to reuse the province field for an alternate reason without needing to recreate any of the database code, validation, processing etc, - eg a simple hook_form_alter to attach an #after_build to the location element would allow changing of the province/state title and then an implementation of hook_location_provinces_alter would allow for a new LOV. And all of this without hacking the module. Example use case - a site that is only targeting one state/province but is wishing to collect a 'region' associated with the location, this change would allow the province field to be reused for just this purpose.
Anyway, I've attached a patch that does just this and hope you consider my request (and yes it is just a one line change).
The drupal_alter is called with the $province array and not the $province[$country] array so the hook implementatons can test the country code and respond accordingly.
Thanks

Comments

larowlan’s picture

StatusFileSize
new673 bytes
yesct’s picture

Issue tags: +location bdragon check

I think we need some committer feedback on this direction

tobiasb’s picture

Status: Needs review » Reviewed & tested by the community
rooby’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new899 bytes

I don't think this should be used for:

...issues in the queue along the lines 'there is a new province in country xx, please update your module' etc...

because we need the location module's provinces to remain as up to date as possible.
That said I know the issue queue review process isn't always as fast as we would like it to be so this would be useful for the interim period until patches are committed.

It would also be useful for custom cases like you mentioned.

I don't think it is the best idea to pass the whole provinces array in though as it is called per country so you only want to send that country's provinces.

Here is a version that passes a second $country parameter to use to determine the country.
Any objections to this approach over the patch in #1?

And for reference, here is an example implementation of the alter hook in case anyone wonders how to use it:

<?php
/**
 * Implementation of hook_location_provinces_alter().
 *
 * @param &$provinces
 *   An array of provinces for the given country.
 * @param $country
 *   The country code of the country that the provinces belong to.
 */
function mymodule_location_provinces_alter(&$provinces, $country) {
  if ($country == 'au') {
    // Remove a province.
    unset($provinces['ACT']);
    // Add/modify provinces.
    $provinces['NSW'] = 'Newer South Wales';
    $provinces['NEW'] = 'A New Province';
  }
}
?>
lpedretti’s picture

Seems reasonable to me, it is also a problem of the 7.x branch.
It's not only the updates, but the fact that anyone may need to use custom naming. For example, i use a webservice from a geo database with hierarchical continent/country/region/state/city and even districts precision, and they have their own code ids. I really think that being able to hook that information to replace the default one is a BIG improvement that would allow for a lot of important customizations with just a few line of code.

Best regards

podarok’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Issue tags: -location bdragon check

all feature requests should be rolled against latest 7.x-3.x-dev and after commit can be backported to 6.x branch

Status: Needs review » Needs work

The last submitted patch, location-provinces_alter-853810-4.patch, failed testing.

Anonymous’s picture

Status: Needs work » Needs review
StatusFileSize
new1.49 KB

Since the #4 patch failed i've created a new one. Hopefully this one succeeds..

It invokes 2 hooks:

  • hook_location_provinces_alter
  • hook_location_provinces__alter
Anonymous’s picture

StatusFileSize
new1.52 KB

hmm. replaced the ternary operator on my previous patch,

Status: Needs review » Needs work

The last submitted patch, 9: location-provinces_alter-853810-9.patch, failed testing.

grisendo’s picture

Status: Needs work » Needs review
grisendo’s picture

#9 works OK for me.

Previous test fail looks like was due to Google Maps service outage.

podarok’s picture

Status: Needs review » Needs work

The last submitted patch, 9: location-provinces_alter-853810-9.patch, failed testing.

sanchiz’s picture

Status: Needs work » Needs review
StatusFileSize
new1.58 KB

Updated patch regarding new updates in the dev branch. Also added $lang_code to the cache key, because it has been lost in the previous patch.

  • podarok_auto committed 0a953b8 on 7.x-3.x authored by sanchiz
    Issue #853810 by willembressers, sanchiz, rooby, larowlan: Added Allow...
podarok’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.