You are here

location_email.module in Location 7.3

Add Email address fields to Location address.

File

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

/**
 * @file
 * Add Email address fields to Location address.
 */

/**
 * Implements hook_locationapi().
 */
function location_email_locationapi(&$location, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'fields':
      return array(
        'email' => t('Email address'),
      );

    // @codingStandardsIgnoreStart
    case 'defaults':
      return array(
        'email' => array(
          'default' => '',
          'collect' => 0,
          'weight' => 25,
        ),
      );

    // @codingStandardsIgnoreEnd
    case 'field_expand':
      if ($a3 == 'email') {
        if (is_array($a4)) {
          $settings = $a4;
        }
        else {

          // On this $op, $a4 is now expected to be an array,
          // but we make an exception for backwards compatibility.
          $settings = array(
            'default' => NULL,
            'weight' => NULL,
            'collect' => $a4,
            'widget' => NULL,
          );
        }
        return array(
          '#type' => 'textfield',
          '#title' => t('Email address'),
          '#size' => 31,
          '#maxlength' => 254,
          '#description' => NULL,
          '#required' => $settings['collect'] == 2,
          '#default_value' => $location,
        );
      }
      break;
    case 'save':
      db_delete('location_email')
        ->condition('lid', $location['lid'])
        ->execute();
      if (!empty($location['email'])) {
        db_insert('location_email')
          ->fields(array(
          'lid' => $location['lid'],
          'email' => $location['email'],
        ))
          ->execute();
      }
      break;
    case 'load':
      $fields = array();
      $email = db_query('SELECT email FROM {location_email} WHERE lid = :lid', array(
        ':lid' => $location['lid'],
      ))
        ->fetchField();
      $fields['email'] = $email ? $email : '';
      return $fields;
    case 'delete':
      db_delete('location_email')
        ->condition('lid', $location['lid'])
        ->execute();
      break;
  }
}

/**
 * Implements hook_views_api().
 */
function location_email_views_api() {
  return array(
    'api' => 3,
  );
}

/**
 * Implements hook_token_list().
 */
function location_email_token_list($type = 'all') {
  if ($type == 'node' || $type == 'user' || $type == 'all') {
    $tokens['location']['location-email_N'] = t('Location Email address (If there are multiple locations per node, N is the iteration, starting with 0)');
    return $tokens;
  }
}

Functions

Namesort descending Description
location_email_locationapi Implements hook_locationapi().
location_email_token_list Implements hook_token_list().
location_email_views_api Implements hook_views_api().