Form Alter for Node Locations

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.


Commentaires
Nice. But shouldn't the
Nice. But shouldn't the after_build function be called "remove_location_countries" to match the name of the function below?
Yes, that must have been a
Yes, that must have been a typo on my part. I've updated the code in the post.
Thanks a lot for this
Thanks a lot for this article. Finally a way for me to customize that form
Andreas