You are here

getdirections_fields.module in Get Directions 7.3

Provides Field module integration for Getdirections

File

modules/getdirections_fields/getdirections_fields.module
View source
<?php

/**
 * @file
 * Provides Field module integration for Getdirections
 */
define('GETDIRECTIONS_FIELDS_PATH', drupal_get_path('module', 'getdirections_fields'));

/**
 * Implements hook_help().
 */
function getdirections_fields_help($path, $arg) {
  switch ($path) {
    case 'admin/help#getdirections':
      $output = '<p>' . t('Provides a getdirections field type.') . '</p>';
      return $output;
  }
}

/**
 * Implements hook_field_info().
 * Define Field API field types.
 *
 * @return
 *   An array whose keys are field type names and whose values are arrays
 *   describing the field type.
 */
function getdirections_fields_field_info() {
  $info = array(
    'getdirections_fields' => array(
      'label' => t('Getdirections Fields'),
      'description' => t('Provide Getdirections Fields.'),
      'default_formatter' => 'getdirections_fields_default',
      'default_widget' => 'getdirections_fields',
      'settings' => array(
        'input_text' => 0,
      ),
    ),
  );
  return $info;
}

/**
 * Implements hook_field_formatter_info().
 *
 * Declare information about a formatter.
 *
 * @return
 *   An array keyed by formatter name. Each element of the array is an associative
 *   array with these keys and values:
 *   - "label": The human-readable label for the formatter.
 *   - "field types": An array of field type names that can be displayed using
 *     this formatter.
 *
 */
function getdirections_fields_field_formatter_info() {
  $formatters = array(
    'getdirections_fields_default' => array(
      'label' => t('Getdirections Field'),
      'field types' => array(
        'getdirections_fields',
      ),
      'settings' => getdirections_fields_field_formatter_settings(),
    ),
    'getdirections_fields_link' => array(
      'label' => t('Getdirections Link'),
      'field types' => array(
        'getdirections_fields',
      ),
      'settings' => getdirections_fields_link_formatter_settings(),
    ),
  );
  return $formatters;
}

/**
 * Implements hook_field_formatter_view().
 * Build a renderable array for a field value.
 *
 * @param $entity_type
 *   The type of $entity.
 * @param $entity
 *   The entity being displayed.
 * @param $field
 *   The field structure.
 * @param $instance
 *   The field instance.
 * @param $langcode
 *   The language associated with $items.
 * @param $items
 *   Array of values for this field.
 * @param $display
 *   The display settings to use, as found in the 'display' entry of instance definitions.
 * @return
 *   A renderable array for the $items, as an array of child elements keyed
 *   by numeric indexes starting from 0.
 *
 */
function getdirections_fields_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  global $language;
  $lang = $langcode ? $langcode : ($entity->language ? $entity->language : $language->language);
  $settings = $display['settings'];
  $module = getdirections_get_current_supported_module();
  $address_field_name = FALSE;
  $loc = FALSE;
  $element = array();
  foreach ($items as $delta => $item) {
    $locative_field_name = $item['locative_field_name'];
    if ($locative_field_name) {
      if ($module == 'getlocations_fields') {
        if (isset($entity->{$locative_field_name}[$lang][$delta])) {
          if ($location = $entity->{$locative_field_name}[$lang][$delta]) {
            $latlon = $location['latitude'] . ',' . $location['longitude'];
            $loc = _getdirections_loadaddress($location);
            if (!$loc) {
              $loc = t('This address');
            }
          }
        }
      }
      elseif ($module == 'location_cck' || $module == 'location_node') {

        // NOT TESTED
        if (isset($entity->{$locative_field_name}[$lang][$delta])) {
          if ($location = $entity->{$locative_field_name}[$lang][$delta]) {
            $latlon = $location['latitude'] . ',' . $location['longitude'];
            $loc = _getdirections_loadaddress($location);
            if (!$loc) {
              $loc = t('This address');
            }
          }
        }
      }
      elseif ($module == 'geofield') {
        if ($location = $entity->{$locative_field_name}[$lang][$delta]) {
          $latlon = $location['lat'] . ',' . $location['lon'];
          $address_field_name = $item['address_field_name'];
          if ($address_field_name && isset($entity->{$address_field_name}[$lang][$delta])) {
            if ($addressfield = $entity->{$address_field_name}[$lang][$delta]) {
              $loc = _getdirections_addressfield_loadaddress($addressfield);
            }
          }
          if (!$loc) {
            $loc = t('This address');
          }
        }
      }
      elseif ($module == 'geolocation') {

        // NOT TESTED
        if ($location = $entity->{$locative_field_name}[$lang][$delta]) {
          $latlon = $location['lat'] . ',' . $location['lng'];
          $address_field_name = $item['address_field_name'];
          if ($address_field_name && isset($entity->{$address_field_name}[$lang][$delta])) {
            if ($addressfield = $entity->{$address_field_name}[$lang][$delta]) {
              $loc = _getdirections_addressfield_loadaddress($addressfield);
            }
          }
          if (!$loc) {
            $loc = t('This address');
          }
        }
      }

      # elseif other modules here
    }
    if (isset($latlon) && !empty($latlon) && getdirections_latlon_check($latlon)) {
      $element = array();
      switch ($display['type']) {
        case 'getdirections_fields_default':
          if (empty($settings)) {
            $settings = getdirections_fields_field_formatter_settings();
          }
          $default_settings = getdirections_fields_field_formatter_settings();
          $default = getdirections_adjust_vars($default_settings['default'], $settings['default']);
          $misc = getdirections_adjust_vars($default_settings['misc'], $settings['misc']);
          $settings['misc'] = $misc;
          $settings['default'] = $default;
          getdirections_setup_map($default, $misc);
          $getdirections_settings = getdirections_get_settings($default, $misc);
          $getdirections_settings['tolatlon'] = $latlon;
          $mapid = getdirections_get_key();
          drupal_add_js(array(
            'getdirections' => array(
              $mapid => $getdirections_settings,
            ),
          ), 'setting');
          $direction_opt = isset($settings['direction_opt']) ? $settings['direction_opt'] : 'to';
          $rawform = drupal_get_form('getdirections_fields_direction_form', $default, $misc, $mapid, $direction_opt, $loc, '', $latlon);
          $form = drupal_render($rawform);
          $element[$delta] = array(
            '#theme' => 'getdirections_fields_show',
            '#form' => $form,
            '#settings' => $settings,
            '#mapid' => $mapid,
          );
          break;
        case 'getdirections_fields_link':
          $entity_get_info = entity_get_info($entity_type);
          $entity_key = $entity_get_info['entity keys']['id'];

          // nid, cid, uid etc
          $entity_id = $entity->{$entity_key};
          $link_text = $settings['text'];
          if ($settings['text_opt'] == 'page') {
            $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 ($entity_title && isset($entity->{$entity_title})) {
              $link_text = $entity->{$entity_title};
            }
          }
          elseif ($settings['text_opt'] == 'address') {
            $link_text = $loc;
          }
          $element[$delta] = array(
            '#theme' => 'getdirections_fields_link',
            '#link_text' => $link_text,
            '#entity_type' => $entity_type,
            '#entity_id' => $entity_id,
            '#dir' => $settings['direction_opt'],
          );
          break;
      }
    }
  }
  return $element;
}

/**
 * Implements hook_field_formatter_settings_summary().
 * Returns a short summary for the current formatter settings of an instance.
 *
 *
 * If an empty result is returned, the formatter is assumed to have no
 * configurable settings, and no UI will be provided to display a settings
 * form.
 *
 *   The field structure.
 * @param $instance
 *   The instance structure.
 * @param $view_mode
 *   The view mode for which a settings summary is requested.
 *
 * @return
 *   A string containing a short summary of the formatter settings.
 */
function getdirections_fields_field_formatter_settings_summary($field, $instance, $view_mode) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $summary = array();
  switch ($display['type']) {
    case 'getdirections_fields_default':
      $default_settings = getdirections_fields_field_formatter_settings();

      // we only show the differences from the defaults
      $summary[] = t('Map Formatter settings');

      // default
      foreach ($default_settings['default'] as $k => $v) {
        if (is_array($v)) {
          foreach ($v as $k1 => $v1) {
            if (isset($settings['default'][$k][$k1]) && $settings['default'][$k][$k1] !== $v1) {
              $summary[] = preg_replace("/_/", " ", $k1) . ': ' . ($settings['default'][$k][$k1] == 0 ? t('No') : ($settings['default'][$k][$k1] == 1 ? t('Yes') : $settings['default'][$k][$k1]));
            }
          }
        }
        else {
          if (isset($settings['default'][$k]) && $settings['default'][$k] !== $v) {
            $summary[] = preg_replace("/_/", " ", $k) . ': ' . ($settings['default'][$k] == 0 ? t('No') : ($settings['default'][$k] == 1 ? t('Yes') : $settings['default'][$k]));
          }
        }
      }

      // misc
      foreach ($default_settings['misc'] as $k => $v) {
        if (isset($settings['misc'][$k]) && $settings['misc'][$k] !== $v) {
          $summary[] = preg_replace("/_/", " ", $k) . ': ' . ($settings['misc'][$k] == '0' ? t('No') : ($settings['misc'][$k] == '1' ? t('Yes') : $settings['misc'][$k]));
        }
      }
      $summary[] = t('Direction: %d', array(
        '%d' => $default_settings['direction_options'][$settings['direction_opt']],
      ));
      break;
    case 'getdirections_fields_link':
      $default_settings = getdirections_fields_link_formatter_settings();
      $summary[] = t('Link Formatter settings');
      $summary[] = t('Text: %t', array(
        '%t' => $settings['text'],
      ));
      $summary[] = t('Option: %o', array(
        '%o' => $default_settings['text_options'][$settings['text_opt']],
      ));
      $summary[] = t('Direction: %d', array(
        '%d' => $default_settings['direction_options'][$settings['direction_opt']],
      ));
      break;
  }
  return implode('<br />', $summary);
}

/**
 * Implements hook_field_formatter_settings_form().
 * Returns form elements for a formatter's settings.
 *
 * @param $field
 *   The field structure being configured.
 * @param $instance
 *   The instance structure being configured.
 * @param $view_mode
 *   The view mode being configured.
 * @param $form
 *   The (entire) configuration form array, which will usually have no use here.
 * @param $form_state
 *   The form state of the (entire) configuration form.
 *
 * @return
 *   The form elements for the formatter settings.
 */
function getdirections_fields_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  drupal_add_js(GETDIRECTIONS_FIELDS_PATH . '/js/getdirections_fields_formatter.js');
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $element = array();
  switch ($display['type']) {
    case 'getdirections_fields_default':
      $default_settings = getdirections_fields_field_formatter_settings();
      if (empty($settings)) {
        $settings = $default_settings;
      }
      else {
        $settings = getdirections_adjust_vars($default_settings, $settings);
      }

      // default settings
      $element['default'] = array(
        '#type' => 'fieldset',
        '#title' => t('Get directions map settings'),
        // This will store all the defaults in one variable.
        '#tree' => TRUE,
      );
      $element['default'] += getdirections_default_settings($settings['default'], '');
      $element['direction_opt'] = array(
        '#type' => 'select',
        '#title' => t('Direction of location'),
        '#default_value' => $settings['direction_opt'],
        '#options' => $settings['direction_options'],
      );

      // misc
      $element['misc'] = array(
        '#type' => 'fieldset',
        '#title' => t('Other settings'),
        // This will store all the defaults in one variable.
        '#tree' => TRUE,
      );
      $element['misc'] += getdirections_misc_settings($settings['misc'], FALSE, FALSE);
      break;
    case 'getdirections_fields_link':
      $element['text'] = array(
        '#type' => 'textfield',
        '#title' => t('Default text'),
        '#description' => t('The text to use if no other option is available.'),
        '#default_value' => $settings['text'],
        '#size' => 25,
      );
      $element['text_opt'] = array(
        '#type' => 'select',
        '#title' => t('Display format'),
        '#default_value' => $settings['text_opt'],
        '#options' => $settings['text_options'],
      );
      $element['direction_opt'] = array(
        '#type' => 'select',
        '#title' => t('Direction'),
        '#default_value' => $settings['direction_opt'],
        '#options' => $settings['direction_options'],
      );
      break;
  }
  return $element;
}
function getdirections_fields_field_formatter_settings() {
  $defaults['default'] = getdirections_defaults();
  $defaults['misc'] = getdirections_misc_defaults();
  $defaults['direction_opt'] = 'to';
  $defaults['direction_options'] = array(
    'to' => t('To'),
    'from' => t('From'),
  );
  return $defaults;
}
function getdirections_fields_link_formatter_settings() {
  return array(
    'text' => t('this location'),
    'text_opt' => 'page',
    'text_options' => array(
      '' => t('None'),
      'page' => t('Page title'),
      'address' => t('Address'),
    ),
    'direction_opt' => 'to',
    'direction_options' => array(
      'to' => t('To'),
      'from' => t('From'),
    ),
  );
}

/**
 * Implements hook_field_widget_info().
 * Expose Field API widget types.
 *
 * @return
 *   An array describing the widget types implemented by the module.
 *
 */
function getdirections_fields_field_widget_info() {
  $info = array(
    'getdirections_fields_default' => array(
      'label' => t('Directions Finder Field'),
      'field types' => array(
        'getdirections_fields',
      ),
      'settings' => array(),
    ),
  );
  return $info;
}

/**
 * Implements hook_field_widget_form().
 * Return the form for a single field widget.
 *
 * @param $form
 *   The form structure where widgets are being attached to. This might be a
 *   full form structure, or a sub-element of a larger form.
 * @param $form_state
 *   An associative array containing the current state of the form.
 * @param $field
 *   The field structure.
 * @param $instance
 *   The field instance.
 * @param $langcode
 *   The language associated with $items.
 * @param $items
 *   Array of default values for this field.
 * @param $delta
 *   The order of this item in the array of subelements (0, 1, 2, etc).
 * @param $element
 *   A form element array containing basic properties for the widget.
 * @return
 *   The form elements for a single widget for this field.
 */
function getdirections_fields_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  switch ($instance['widget']['type']) {
    case 'getdirections_fields_default':

      // is this real or a demo in settings
      $active = TRUE;
      if (empty($element['#entity'])) {
        $active = FALSE;
      }
      $entity_type = $element['#entity_type'];
      $bundle = $element['#bundle'];
      $module = getdirections_get_current_supported_module();
      $fieldnames = array();
      $query = db_select('field_config', 'f');
      $query
        ->fields('i', array(
        'field_name',
        'data',
      ));
      $query
        ->join('field_config_instance', 'i', 'f.id=i.field_id');
      $query
        ->condition('i.bundle', $bundle)
        ->condition('f.module', $module)
        ->condition('i.entity_type', $entity_type)
        ->condition('f.active', 1);
      $rows = $query
        ->execute();
      foreach ($rows as $row) {
        $data = unserialize($row->data);
        $fieldnames[$row->field_name] = $data['label'];
      }

      // addressfield support
      $address_fieldnames = array();
      if ($module == 'geofield' || $module == 'geolocation') {
        $query = db_select('field_config', 'f');
        $query
          ->fields('i', array(
          'field_name',
          'data',
        ));
        $query
          ->join('field_config_instance', 'i', 'f.id=i.field_id');
        $query
          ->condition('i.bundle', $bundle)
          ->condition('f.module', 'addressfield')
          ->condition('i.entity_type', $entity_type)
          ->condition('f.active', 1);
        $rows = $query
          ->execute();
        foreach ($rows as $row) {
          $data = unserialize($row->data);
          $address_fieldnames[$row->field_name] = $data['label'];
        }
      }
      $cardinality = $field['cardinality'];
      $settings = $field['settings'];

      // Wrap in a fieldset for single fields
      if ($cardinality == 1) {
        $element['#type'] = 'fieldset';
        $element['#collapsible'] = TRUE;
        $element['#collapsed'] = FALSE;
      }
      if (!empty($fieldnames)) {
        $element['#delta'] = $delta;
        $field_name = '';
        if (isset($field['field_name'])) {
          $field_name = $field['field_name'];
          $items[$delta]['field_name'] = $field_name;
        }
        $dval = isset($items[$delta]['locative_field_name']) ? $items[$delta]['locative_field_name'] : (isset($instance['default_value'][$delta]['locative_field_name']) ? $instance['default_value'][$delta]['locative_field_name'] : '');

        // vbo
        if ($active && module_exists('views_bulk_operations') && isset($settings['input_text']) && $settings['input_text']) {
          $element['locative_field_name'] = array(
            '#type' => 'textfield',
            '#title' => t('Location Field'),
            '#description' => t('Field to take locative data from'),
            '#default_value' => $dval,
            '#size' => 30,
          );
        }
        else {

          // items only see which field, no choice
          if ($active && $dval) {
            $element['locative_field_name'] = array(
              '#type' => 'value',
              '#value' => $dval,
            );
            $element['locative_field_name_markup'] = array(
              '#markup' => '<p>' . t('Locative data taken from !f', array(
                '!f' => $fieldnames[$dval],
              )) . '</p>',
            );
          }
          else {
            $element['locative_field_name'] = array(
              '#type' => 'select',
              '#title' => t('Location Field'),
              '#options' => $fieldnames,
              '#description' => t('Field to take locative data from'),
              '#default_value' => $dval,
            );
          }
        }

        // vbo
        $adval = isset($items[$delta]['address_field_name']) ? $items[$delta]['address_field_name'] : (isset($instance['default_value'][$delta]['address_field_name']) ? $instance['default_value'][$delta]['address_field_name'] : '');
        if (!empty($address_fieldnames) && $active && module_exists('views_bulk_operations') && isset($settings['input_text']) && $settings['input_text']) {
          $element['address_field_name'] = array(
            '#type' => 'textfield',
            '#title' => t('Address Field'),
            '#description' => t('Field to take address data from'),
            '#default_value' => $adval,
            '#size' => 30,
          );
        }
        else {
          if (!empty($address_fieldnames)) {
            $element['address_field_name'] = array(
              '#type' => 'select',
              '#title' => t('Address Field'),
              '#options' => array(
                '' => t('No address shown'),
              ) + $address_fieldnames,
              '#description' => t('Field to take address data from'),
              '#default_value' => $adval,
            );
          }
          else {
            $element['address_field_name'] = array(
              '#type' => 'value',
              '#value' => '',
            );
          }
        }
      }
      else {
        if (!$active) {
          $element['some_info'] = array(
            '#type' => 'markup',
            '#markup' => '<p>' . t('You must attach an instance of !m', array(
              '!m' => $module,
            )),
          );
        }
      }
      break;
  }
  return $element;
}

/**
 * Implements hook_field_widget_error().
 *
 * hook_field_widget_error() lets us figure out what to do with errors
 * we might have generated in hook_field_validate(). Generally, we'll just
 * call form_error().
 *
 */
function getdirections_fields_field_widget_error($element, $error, $form, &$form_state) {
  switch ($error['error']) {
    case 'getdirections_fields_field_invalid':
      form_error($element, $error['message']);
      break;
  }
}

/**
 * Implements hook_field_is_empty().
 * Define what constitutes an empty item for a field type.
 * hook_field_is_emtpy() is where Drupal asks us if this field is empty.
 * Return TRUE if it does not contain data, FALSE if it does. This lets
 * the form API flag an error when required fields are empty.
 *
 * @param $item
 *   An item that may or may not be empty.
 * @param $field
 *   The field to which $item belongs.
 * @return
 *   TRUE if $field's type considers $item not to contain any data;
 *   FALSE otherwise.
 */
function getdirections_fields_field_is_empty($item, $field) {
  return FALSE;
}

/**
 * Implements hook_field_settings_form().
 * Add settings to a field settings form.
 *
 * Invoked from field_ui_field_settings_form() to allow the module defining the
 * field to add global settings (i.e. settings that do not depend on the bundle
 * or instance) to the field settings form. If the field already has data, only
 * include settings that are safe to change.
 *
 * @todo: Only the field type module knows which settings will affect the
 * field's schema, but only the field storage module knows what schema
 * changes are permitted once a field already has data. Probably we need an
 * easy way for a field type module to ask whether an update to a new schema
 * will be allowed without having to build up a fake $prior_field structure
 * for hook_field_update_forbid().
 *
 * @param $field
 *   The field structure being configured.
 * @param $instance
 *   The instance structure being configured.
 * @param $has_data
 *   TRUE if the field already has data, FALSE if not.
 *
 * @return
 *   The form definition for the field settings.
 */
function getdirections_fields_field_settings_form($field, $instance, $has_data) {
  $settings = $field['settings'];
  if (empty($settings)) {
    $settings = getdirections_fields_field_info();
  }
  $form = array();

  // input_text
  if (module_exists('views_bulk_operations')) {
    $form['input_text'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use a textfield'),
      '#description' => t('Select this setting if you intend to use VBO to update data.'),
      '#default_value' => $settings['input_text'],
      '#return_value' => 1,
    );
  }
  else {
    $form['input_text'] = array(
      '#type' => 'value',
      '#value' => 0,
    );
  }
  return $form;
}

/**
 * The getdirections form
 *
 */
function getdirections_fields_direction_form($form, &$form_state, $default, $misc, $mapid, $fromto = '', $loc = '', $country = '', $latlon = '') {
  $form = array();
  $form += _getdirections_direction_form($default, $misc, $mapid, $fromto, $loc, $country, $latlon);
  $settings = array();
  $settings['default'] = $default;
  $settings['misc'] = $misc;
  $form['settings'] = array(
    '#type' => 'value',
    '#value' => $settings,
  );
  unset($form['#theme']);
  $form['#theme'] = 'getdirections_direction_form';
  return $form;
}

/**
 * Implements hook_theme().
 *
 * This lets us tell Drupal about our theme functions and their arguments.
 */
function getdirections_fields_theme() {
  return array(
    'getdirections_fields_show' => array(
      'variables' => array(
        'form' => NULL,
        'settings' => array(),
        'mapid' => '',
      ),
    ),
    'getdirections_fields_link' => array(
      'variables' => array(
        'link_text' => '',
        'entity_type' => '',
        'entity_id' => 0,
        'dir' => 'to',
      ),
    ),
  );
}
function theme_getdirections_fields_show($variables) {
  $form = $variables['form'];
  $mapid = $variables['mapid'];
  $settings = $variables['settings'];
  $getdirections_defaults = $settings['default'];
  $getdirections_misc = $settings['misc'];
  $width = $settings['default']['width'];
  $height = $settings['default']['height'];
  $output = '';
  $output .= $form;
  if ($getdirections_misc['show_distance']) {
    $output .= '<div id="getdirections_show_distance_' . $mapid . '"></div>';
  }
  if ($getdirections_misc['show_duration']) {
    $output .= '<div id="getdirections_show_duration_' . $mapid . '"></div>';
  }
  $help = '';
  if ($getdirections_defaults['use_advanced']) {
    if ($getdirections_defaults['waypoints'] > 0 && !$getdirections_defaults['advanced_alternate']) {
      $help = t('Drag <img src="http://labs.google.com/ridefinder/images/mm_20_!c.png"> to activate a waypoint', array(
        '!c' => $getdirections_defaults['waypoint_color'],
      ));
      if ($getdirections_defaults['advanced_autocomplete'] && $getdirections_defaults['advanced_autocomplete_via']) {
        $help .= ' ' . t('or use the Autocomplete boxes');
      }
    }
    elseif ($getdirections_defaults['advanced_alternate']) {
      $help = t('You can drag the route to change it');
    }
  }
  $output .= '<div id="getdirections_help_' . $mapid . '">' . $help . '</div>';
  $header = array();
  $rows[] = array(
    array(
      'data' => '<div id="getdirections_map_canvas_' . $mapid . '" style="width: ' . $width . '; height: ' . $height . '" ></div>',
      'valign' => 'top',
      'align' => 'center',
      'class' => array(
        'getdirections-map',
      ),
    ),
    array(
      'data' => ($getdirections_defaults['use_advanced'] && $getdirections_defaults['advanced_alternate'] ? '<button id="getdirections-undo-' . $mapid . '">' . t('Undo') . '</button>' : '') . '<div id="getdirections_directions_' . $mapid . '"></div>',
      'valign' => 'top',
      'align' => 'left',
      'class' => array(
        'getdirections-list',
      ),
    ),
  );
  $output .= '<div class="getdirections">' . theme('table', array(
    'header' => $header,
    'rows' => $rows,
  )) . '</div>';
  return $output;
}
function theme_getdirections_fields_link($variables) {
  $link_text = $variables['link_text'];
  $entity_type = $variables['entity_type'];
  $entity_id = $variables['entity_id'];
  $direction = $variables['dir'];
  $output = '';
  $direction_text = t('to');
  if ($direction == 'from') {
    $direction_text = t('from');
  }
  $path = 'getdirections/' . $entity_type . '/' . $direction . '/' . $entity_id;
  $link = t('Get directions !t !l', array(
    '!t' => $direction_text,
    '!l' => l($link_text, $path),
  ));
  $output .= '<div class="getdirections_link">' . $link . '</div>';
  return $output;
}

/**
 * Implements hook_field_info_alter().
 */
function getdirections_fields_field_info_alter(&$field_info) {
  $field_info['getdirections_fields']['property_type'] = 'getdirections_fields';
  $field_info['getdirections_fields']['property_callbacks'][] = 'getdirections_fields_property_callback';
}

/**
 * Property callback for getdirections fields.
 */
function getdirections_fields_property_callback(&$info, $entity_type, $field, $instance, $field_type) {
  $property =& $info[$entity_type]['bundles'][$instance['bundle']]['properties'][$field['field_name']];
  $property['getter callback'] = 'entity_metadata_field_verbatim_get';
  $property['setter callback'] = 'entity_metadata_field_verbatim_set';
  foreach (getdirections_fields_key_map() as $key => $item) {
    $property['property info'][$key] = array(
      'type' => $item['type'],
      'label' => $item['label'],
      'description' => $item['description'],
      'getter callback' => 'entity_property_verbatim_get',
      'setter callback' => 'entity_property_verbatim_set',
    );
  }
  unset($property['query callback']);
}
function getdirections_fields_key_map() {
  $keys = array(
    'locative_field_name' => array(
      'type' => 'text',
      'label' => t('Name'),
      'description' => t('The locative field name'),
    ),
    'address_field_name' => array(
      'type' => 'text',
      'label' => t('Name'),
      'description' => t('The address field name'),
    ),
  );
  return $keys;
}

Functions

Namesort descending Description
getdirections_fields_direction_form The getdirections form
getdirections_fields_field_formatter_info Implements hook_field_formatter_info().
getdirections_fields_field_formatter_settings
getdirections_fields_field_formatter_settings_form Implements hook_field_formatter_settings_form(). Returns form elements for a formatter's settings.
getdirections_fields_field_formatter_settings_summary Implements hook_field_formatter_settings_summary(). Returns a short summary for the current formatter settings of an instance.
getdirections_fields_field_formatter_view Implements hook_field_formatter_view(). Build a renderable array for a field value.
getdirections_fields_field_info Implements hook_field_info(). Define Field API field types.
getdirections_fields_field_info_alter Implements hook_field_info_alter().
getdirections_fields_field_is_empty Implements hook_field_is_empty(). Define what constitutes an empty item for a field type. hook_field_is_emtpy() is where Drupal asks us if this field is empty. Return TRUE if it does not contain data, FALSE if it does. This lets the form API flag an…
getdirections_fields_field_settings_form Implements hook_field_settings_form(). Add settings to a field settings form.
getdirections_fields_field_widget_error Implements hook_field_widget_error().
getdirections_fields_field_widget_form Implements hook_field_widget_form(). Return the form for a single field widget.
getdirections_fields_field_widget_info Implements hook_field_widget_info(). Expose Field API widget types.
getdirections_fields_help Implements hook_help().
getdirections_fields_key_map
getdirections_fields_link_formatter_settings
getdirections_fields_property_callback Property callback for getdirections fields.
getdirections_fields_theme Implements hook_theme().
theme_getdirections_fields_link
theme_getdirections_fields_show

Constants

Namesort descending Description
GETDIRECTIONS_FIELDS_PATH @file Provides Field module integration for Getdirections