-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocation_county.module
More file actions
74 lines (64 loc) · 1.83 KB
/
location_county.module
File metadata and controls
74 lines (64 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
// $Id$
/**
* @file
* Add county fields to Location address.
*/
/**
* Implementation of hook_locationapi().
*/
function location_county_locationapi(&$location, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'fields':
return array('county' => t('County'));
case 'defaults':
return array(
'county' => array('default' => '', 'collect' => 0, 'weight' => 9),
);
case 'field_expand':
if ($a3 == 'county') {
return array(
'#type' => 'textfield',
'#title' => t('County'),
'#size' => 20,
'#maxlength' => 45,
'#description' => NULL,
'#required' => ($a4 == 2),
'#default_value' => $location,
);
}
break;
case 'save':
db_query('DELETE FROM {location_county} WHERE lid = %d', $location['lid']);
if (!empty($location['county'])) {
db_query("INSERT INTO {location_county} (lid, county) VALUES (%d, '%s')", $location['lid'], $location['county']);
}
break;
case 'load':
$fields = array('county' => '');
if ($row = db_fetch_object(db_query('SELECT county FROM {location_county} WHERE lid = %d', $location['lid']))) {
$fields['county'] = $row->county;
}
return $fields;
case 'delete':
db_query('DELETE FROM {location_county} WHERE lid = %d', $location['lid']);
break;
}
}
/**
* Implementation of hook_views_api().
*/
function location_county_views_api() {
return array(
'api' => 2,
);
}
/**
* Implementation of hook_token_list().
*/
function location_county_token_list($type = 'all') {
if ($type == 'node' || $type == 'user' || $type == 'all') {
$tokens['location']['location-county_N'] = t('Location County (If there are multiple locations per node, N is the iteration, starting with 0)');
return $tokens;
}
}