You are here

location_phone.module in Location 7.4

Add phone number fields to Location address.

File

contrib/location_phone/location_phone.module
View source
<?php

/**
 * @file
 * Add phone number fields to Location address.
 */

/**
 * Implementation of hook_locationapi().
 */
function location_phone_locationapi(&$location, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'fields':
      return array(
        'phone' => t('Phone number'),
      );
    case 'defaults':
      return array(
        'phone' => array(
          'default' => '',
          'collect' => 0,
          'weight' => 25,
        ),
      );
    case 'field_expand':
      if ($a3 == 'phone') {
        return array(
          '#type' => 'textfield',
          '#title' => t('Phone number'),
          '#size' => 31,
          '#maxlength' => 31,
          '#description' => NULL,
          '#required' => $a4 == 2,
          '#default_value' => $location,
        );
      }
      break;
    case 'save':
      db_query('DELETE FROM {location_phone} WHERE lid = :lid', array(
        ':lid' => $location['lid'],
      ));
      if (!empty($location['phone'])) {
        db_query("INSERT INTO {location_phone} (lid, phone) VALUES (:lid, :phone)", array(
          ':lid' => $location['lid'],
          ':phone' => $location['phone'],
        ));
      }
      break;
    case 'load':
      $fields = array(
        'phone' => '',
      );
      if ($result = db_query('SELECT phone FROM {location_phone} WHERE lid = :lid', array(
        ':lid' => $location['lid'],
      ))
        ->fetchObject()) {
        $fields['phone'] = $result->phone;
      }
      return $fields;
    case 'delete':
      db_query('DELETE FROM {location_phone} WHERE lid = :lid', array(
        ':lid' => $location['lid'],
      ));
      break;
  }
}

/**
 * Implementation of hook_views_api().
 */
function location_phone_views_api() {
  return array(
    'api' => 3,
  );
}

/**
 * Implementation of hook_token_list().
 */
function location_phone_token_list($type = 'all') {
  if ($type == 'node' || $type == 'user' || $type == 'all') {
    $tokens['location']['location-phone_N'] = t('Location Phone number (If there are multiple locations per node, N is the iteration, starting with 0)');
    return $tokens;
  }
}

Functions

Namesort descending Description
location_phone_locationapi Implementation of hook_locationapi().
location_phone_token_list Implementation of hook_token_list().
location_phone_views_api Implementation of hook_views_api().