Change the Labels on the Form for Location Module

If you have ever needed to do something "simple" like change the form label from something like "Additional" to "Apartment" you know how difficult that can be. Apparently the location module does not use the Form API like other modules so you can't simply do a hook_form_alter().

I stumbled across the following little piece to handle just this sort of situation. Drop the following in your custom module and you can easily change labels.

/**
* Implementation of hook_locationapi().
*/
function YOUR-MODULE-NAME_locationapi(&$obj, $op, $a3 = NULL, $a4 = NULL, $a5 = NULL) {
  switch ($op) {
    case 'field_expand':
      switch ($a3) {
        case 'street':
          return array(
            '#type'           => 'textfield',
            '#title'          => t('Address 1'),
            '#default_value'  => $obj,
            '#size'           => 64,
            '#maxlength'      => 64,
            '#description'    => t(''),
            '#attributes'     => NULL,
            '#required'       => ($a4 == 2),
          );
        case 'additional':
          return array(
            '#type'           => 'textfield',
            '#title'          => t('Address 2'),
            '#default_value'  => $obj,
            '#size'           => 64,
            '#maxlength'      => 64,
            '#description'    => t(''),
            '#attributes'     => NULL,
            '#required'       => ($a4 == 2),
          );         
      }
  }
}

The above code simply changes the "Street" label to "Address 1" and the "Additional" label to "Address 2"

Contact Me

Feel free to contact me.

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.