function location_email_locationapi in Location 7.3
Implements hook_locationapi().
File
- contrib/
location_email/ location_email.module, line 11 - Add Email address fields to Location address.
Code
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;
}
}