You are here

function location_fax_locationapi in Location 7.3

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

Implements hook_locationapi().

File

contrib/location_fax/location_fax.module, line 11
Add fax number fields to Location address.

Code

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

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

    // @codingStandardsIgnoreEnd
    case 'field_expand':
      if ($a3 == 'fax') {
        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('Fax number'),
          '#size' => 31,
          '#maxlength' => 31,
          '#description' => NULL,
          '#required' => $settings['collect'] == 2,
          '#default_value' => $location,
        );
      }
      break;
    case 'save':
      db_delete('location_fax')
        ->condition('lid', $location['lid'])
        ->execute();
      if (!empty($location['fax'])) {
        db_insert('location_fax')
          ->fields(array(
          'lid' => $location['lid'],
          'fax' => $location['fax'],
        ))
          ->execute();
      }
      break;
    case 'load':
      $fields = array();
      $fax = db_query('SELECT fax FROM {location_fax} WHERE lid = :lid', array(
        ':lid' => $location['lid'],
      ))
        ->fetchField();
      $fields['fax'] = $fax ? $fax : '';
      return $fields;
    case 'delete':
      db_delete('location_fax')
        ->condition('lid', $location['lid'])
        ->execute();
      break;
  }
}