You are here

function location_phone_locationapi in Location 7.3

Same name and namespace in other branches
  1. 5.3 contrib/location_phone/location_phone.module \location_phone_locationapi()
  2. 5 contrib/location_phone/location_phone.module \location_phone_locationapi()
  3. 6.3 contrib/location_phone/location_phone.module \location_phone_locationapi()
  4. 7.5 contrib/location_phone/location_phone.module \location_phone_locationapi()
  5. 7.4 contrib/location_phone/location_phone.module \location_phone_locationapi()

Implements hook_locationapi().

File

contrib/location_phone/location_phone.module, line 11
Add phone number fields to Location address.

Code

function location_phone_locationapi(&$location, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'fields':
      return array(
        'phone' => t('Phone number'),
      );

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

    // @codingStandardsIgnoreEnd
    case 'field_expand':
      if ($a3 == 'phone') {
        return array(
          '#type' => 'textfield',
          '#title' => t('Phone number'),
          '#size' => 31,
          '#maxlength' => 31,
          '#description' => NULL,
          '#required' => $a4['collect'] == 2,
          '#default_value' => $location,
        );
      }
      break;
    case 'save':
      db_delete('location_phone')
        ->condition('lid', $location['lid'])
        ->execute();
      if (!empty($location['phone'])) {
        db_insert('location_phone')
          ->fields(array(
          'lid' => $location['lid'],
          'phone' => $location['phone'],
        ))
          ->execute();
      }
      break;
    case 'load':
      $fields = array();
      $phone = db_query('SELECT phone FROM {location_phone} WHERE lid = :lid', array(
        ':lid' => $location['lid'],
      ))
        ->fetchField();
      $fields['phone'] = $phone ? $phone : '';
      return $fields;
    case 'delete':
      db_delete('location_phone')
        ->condition('lid', $location['lid'])
        ->execute();
      break;
  }
}