Skip to content

Instantly share code, notes, and snippets.

@evandonovan
Created May 17, 2010 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evandonovan/404285 to your computer and use it in GitHub Desktop.
Save evandonovan/404285 to your computer and use it in GitHub Desktop.
gmap marker popup via AHAH code
<?php
// following is excerpted from um_common.module:
// service area vid
define("SERVICE_AREA_VID", 32);
/**
* Implements hook_menu()
* Creates Gmap rendering callbacks for popups.
*/
function um_common_menu() {
// marker popup callback
$items['gmap-popup/%node'] = array(
'page callback' => 'um_common_node_popup_render',
'page arguments' => array(1),
'access callback' => 'gmap_node_map_access',
'access arguments' => array(1),
'weight' => 2,
'type' => MENU_CALLBACK
);
return $items;
}
/* Page callback for single marker popup */
function um_common_node_popup_render(&$node) {
print theme("node_marker_popup", $node);
}
function um_common_theme() {
return array(
// call using theme('node_marker_popup', $node)
// provides templated theming function to um_common_node_popup_render()
'node_marker_popup' => array(
'template' => 'node-marker-popup',
'arguments' => array(
'node' => null,
),
),
/* adds preprocess to set up variables for the marker popup */
'preprocess_method' => array(
'template' => 'node_marker_popup',
'arguments' => array('node' => null),
),
);
}
/* Preprocess for node_marker_popup */
function um_common_preprocess_node_marker_popup(&$vars) {
if(isset($vars['node']->location)) {
$vars['address'] = theme('location', $vars['node']->location);
}
switch($vars['node']->type) {
case 'volunteer_opportunity':
$title_text = 'Volunteer in ' . $vars['node']->title;
if(isset($vars['node']->taxonomy) && is_array($vars['node']->taxonomy)) {
foreach($vars['node']->taxonomy as $term) {
if ($term->vid == SERVICE_AREA_VID) {
$terms[] = array('href' => 'taxonomy/term/' . $term->tid, 'title' => $term->name);
}
}
$vars['service_areas'] = theme('links', $terms, array('class' => 'links', 'style' => 'display: inline;'));
}
if(isset($vars['node']->field_volopp_org_name[0]['value'])) {
$vars['organization_name'] = $vars['node']->field_volopp_org_name[0]['value'];
}
break;
default:
$title_text = $vars['node']->title;
$node_title = $vars['node']->title;
}
$vars['node_link'] = l($vars['node']->title, $vars['node']->nid, array('attributes' => array('class' => 'opp-title', 'title' => 'Volunteer in ' . $node_title)));
}
?>
<?php and in node-marker-popup.tpl.php (same directory as module) ?>
<?php
// $Id
/**
* @file node-marker-popup.tpl.php
*
* Theme implementation to display a marker popup.
* Different variables are available based on node type.
*
* Available variables:
* - $node_link: the node title, linked to the node.
* - $address: the address, if there is one.
* For volunteer opportunities only:
* - $organization_name: the name of the organization
* - $service_areas: the terms from the service areas taxonomy, as links
*
* @see um_common_preprocess_node_marker_popup()
*/
?>
<?php if($node_link) { print $node_link; } ?>
<br />
<?php if($organization_name) { ?>
<strong>Organization:</strong> <?php print $organization_name; ?>
<br />
<?php } ?>
<?php if($service_areas) { ?>
<strong>Service Area:</strong> <?php print $service_areas; ?>
<br />
<?php } ?>
<?php if($address) { ?>
<strong>Address:</strong> <?php print $address; ?>
<br />
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment