You are here

function getdirections_direction in Get Directions 7.3

Same name and namespace in other branches
  1. 6.2 getdirections.module \getdirections_direction()
  2. 6 getdirections.module \getdirections_direction()
  3. 7.2 getdirections.module \getdirections_direction()

Function to setup the map and form

Parameters

string $direction: Optional. The direction the supplied input applies to

string $location: Optional. The string to search with

string $country: Optional. The country

string $latlon: Optional. Comma delimited string containing latitude and longitude

Return value

Returns the themed map and form

4 calls to getdirections_direction()
getdirections_direction_box in ./getdirections.module
for colorbox and suchlike
getdirections_entity_setlocation in ./getdirections.module
Function to setup the map
getdirections_entity_setlocations in ./getdirections.module
Function to setup the map
getdirections_setlocation_id in ./getdirections.module
Function to setup the map and form
1 string reference to 'getdirections_direction'
getdirections_menu in ./getdirections.module
Implement hook_menu().

File

./getdirections.module, line 298
Fetches google map directions.

Code

function getdirections_direction($direction = '', $location = '', $country = '', $latlon = '', $entity_id = 0, $entity_type = 'node', $width = '', $height = '') {
  if (!getdirections_check()) {
    return t('You need to !c first.', array(
      '!c' => l('configure Getdirections', 'admin/config/services/getdirections'),
    ));
  }
  $getdirections_defaults = getdirections_defaults();
  $getdirections_misc = getdirections_misc_defaults();
  getdirections_setup_map($getdirections_defaults, $getdirections_misc);
  $getdirections_settings = getdirections_get_settings($getdirections_defaults, $getdirections_misc);
  $mapid = getdirections_get_key();
  drupal_add_js(array(
    'getdirections' => array(
      $mapid => $getdirections_settings,
    ),
  ), 'setting');
  if ($getdirections_misc['keep_title'] && $entity_id && $direction) {
    if ($direction == 'to') {
      $direction_translated = t('to');
    }
    elseif ($direction == 'from') {
      $direction_translated = t('from');
    }

    // entityfy this
    if ($entity_type == 'term') {
      $entity_type = 'taxonomy_term';
    }

    // is it location enabled?
    if (getdirections_check_entity_type($entity_type)) {
      $entity_get_info = entity_get_info($entity_type);
      if ($entity_get_info['fieldable']) {
        $load_hook = $entity_get_info['load hook'];
        $entity = $load_hook($entity_id);
        $entity_title = '';
        if (isset($entity_get_info['entity keys']['label'])) {
          $entity_title = $entity_get_info['entity keys']['label'];
        }
        elseif ($entity_type == 'user') {
          $entity_title = 'name';
        }
        if (isset($entity->{$entity_title})) {
          $title = $entity->{$entity_title};
          drupal_set_title(t('Get directions @d !t', array(
            '@d' => $direction_translated,
            '!t' => $title,
          )));
        }
      }
    }
  }
  if (empty($width)) {
    $width = $getdirections_defaults['width'];
  }
  if (empty($height)) {
    $height = $getdirections_defaults['height'];
  }

  // remove brackets if any
  $latlon = preg_replace("/^\\(|\\)\$/", '', $latlon);
  $raw_form = drupal_get_form('getdirections_direction_form', $mapid, $direction, $location, $country, $latlon);
  $form = render($raw_form);
  return theme('getdirections_show', array(
    'form' => $form,
    'mapid' => $mapid,
    'width' => $width,
    'height' => $height,
    'entity_id' => $entity_id,
    'entity_type' => $entity_type,
  ));
}