Hi, I'm currently try to use the location_element in some forms, I have a note, an a support request:

The note is

I use the location_settings element to make a location settings, which I store in variables, I do this:

function mymodule_admin_settings() {
  $form = array();

  $form[MYMODULE_LOCATION_SETTINGS] = array(
    '#title' => t('Users locative information'),
    '#description' => t('This options must have the given fields: street, addional, province, city, country'),
    '#type' => 'location_settings',
    '#default_value' => variable_get(MYMODULE_LOCATION_SETTINGS, NULL),
  );

  return system_settings_form($form);
}

The MYMODULE_LOCATION_SETTINGS is just a string which contains the variable name. The problem is, when I get back my settings, I have to do a method like this one...

function _mymodule_get_location_settings() {
  if ($fields = variable_get(MYMODULE_LOCATION_SETTINGS, NULL)) {
    $settings = array('form' => array('fields' => $fields));
    return $settings;
  }
}

...in order to use the settings as #location_settings in my location_element.

I just don't understand why the value returned by the location_settings form element is different that the one we have to use in the location_element, I think this is a bit inconsistent.

My support request is

I get back my location from a custom database, so, my field names are not the same as yours, and I don't have a lid, so, to get back my location, I have somehow to convert it to an array corresping to those you use into your API, with a method like:

function mymodule_get_client_location(&$account) {
  if ($object = mymodule_get_client($account)) {
    $location = array(
      'street' => $object->address1,
      'additional' => $object->address2,
      'province' => $object->state,
      'city' => $object->city,
      'postal_code' => $object->zipcode,
      'country' => $object->country,
    );
    return $location;
  }
}

Where $object is a row got from my database.

Then, in order to use the location_element form element, I put something like:

      $form['my_location'] = array(
        '#type' => 'location_element',
        '#required' => TRUE,
        '#location_settings' => _mymodule_get_location_settings(),
        '#default_value' => mymodule_get_client_location($account),
      );

Ok, all seems to be good here, but I did a lot (and when I write "a lot", it's "A LOT" you must read) of differents code combinaison to try to make my location_element use my location array as default value, but it does not want it, I just can't set default value for the element!

Is there a magical solution to get my values in my form element ?

Comments

yesct’s picture

Status: Active » Postponed (maintainer needs more info)
Issue tags: +Location theming, +location importing

pounard , I'm not an expert location user, and not a maintainer, but I dont really understand your question. Could you post back and update us on what else you have tried, and maybe also try to restate your question? Sorry I cannot be of more direct assistance (I'm trying to clean up the issue queue). I'm tagging with things I think might be related. Are you trying to import data into location?

pounard’s picture

The question was, I just cant use other defaults than the one defined in my configuration form.
The fact is I don't use location module's table to store data, but an external source. And as I don't have a lid, I can't fill the form.

So, I found another way to do it, I load my defaults, then change ['default'] values for each sub element, just after loading, then spawn my location_element form element with these modified defaults. It works.

pounard’s picture

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