Closed (fixed)
Project:
Location
Version:
7.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
20 Sep 2009 at 03:01 UTC
Updated:
18 Jan 2012 at 22:19 UTC
I'd like to create a new format for displaying a location (in my case, city, state). Is there a way to do that without modifying the location module (i.e. I don't know that my requirement is general enough to be included in the regular distribution, and I'd rather not fork it locally)? Also, how would I do it in either case?
Thanks.
Colin
Comments
Comment #1
ccprog commentedYou can modify location.tpl.php and then place it in your theme folder. If you need a format for a specific country, use location-xx.tpl.php, where xx is the standard country code (a list of recognized codes is in function location_get_iso3166_list at the bottom of file location.inc). The files will be automatically detected and used by the theming engine.
Comment #2
colin_young commentedBest as I can tell, that just lets me modify the output for the existing formatters (e.g. address, address with map, etc.) and if I modified that to remove the fields I don't want to see, it's going to affect all the other formats. At least that's how I understand it. I'm guessing that what I'd need to do is somehow provide location.tpl.php just the values I want output, but so far how to do that has eluded me.
Comment #3
ccprog commentedI am not completely sure whether I understand what you want to do. If you want to format locations depending on some conditions (for example depending on the node type they appear in), you might have to look into http://drupal.org/node/223430 and http://drupal.org/node/223440 and set up an additional preprocessor function.
Besides function template_preprocess_location from location.module you can have your own [theme_name]_preprocess_location in your theme's template.php and modify the way the formatter is called. From your description, you have two possible avenues: Either you simply remove some variables and let the standard formatter handle the output, or you set up specialized formatters and use template suggestions. (Look at the last if-clause in the module's function. It is responsable for naming country-specific template suggestions.)
Comment #4
colin_young commentedI'd prefer to be able to specify the format at the time of defining my view or wherever I'm using it like I can with the included drop-down, by having my custom format appear in that drop-down (e.g. I'd like to add address without lat/long since I've still got a need to sometimes display lat/long so I can't just take it out of the standard formatter). Maybe it's not possible with the current location module.
As a work-around I can probably use a technique from the links you've provided to format my display (it's also possible that I'll end up needing only one format) once I understand them, but I thought I'd see if there was a provided way to extend the supplied formats and expose new formats in the UI.
It sounds like what I've really come up with is a possible feature request.
Thanks.
Comment #5
rooby commentedTo do this is the realm of a custom module that provides a new cck formatter (or if it is useful to everyone a patch for the location_cck module that provides a new formatter.
For details on creating a new formatter check out the code in location_cck.
In particular hook_theme() and its related theme functions and hook_field_formatter_info().
And this post might be useful - http://www.lullabot.com/articles/creating-custom-cck-fields
Closing due to inactivity but please reopen if you need clarification.
Comment #7
xaqroxI was facing the same problem, using Drupal 7. I found my solution on these Field API pages:
http://api.drupal.org/api/drupal/modules--field--field.api.php/group/fie...
http://api.drupal.org/api/drupal/modules--field--field.api.php/function/...
http://api.drupal.org/api/drupal/modules--field--field.api.php/function/...