Form Alter for Node Locations

Dec 15, 2009 · by Suzanne Dergacheva
north america map

Form Alter for Node Locations

Dec 15, 2009 · by Suzanne Dergacheva


The location module is a key component to many Drupal projects, but it can be tricky to work with. It's very common to want to alter the way the location form appears, but the location module doesn't make this easy.

For example, we're working on a project with a North American focus, so locations have to be limited to Canada, the United States, and Mexico. So one of the requirements is to only allow users to select these countries when creating a new location.

While locations can't be edited like other fields, it's possible to alter it through the form's after_build property. All this requires is a regular form alter, plus an extra function to unset the unwanted form elements.