1
|
<?php
|
2
|
|
3
|
/*
|
4
|
* @file
|
5
|
* Devel Generate for addressfield module
|
6
|
*
|
7
|
*/
|
8
|
|
9
|
/*
|
10
|
* Implements hook_devel_generate();
|
11
|
*/
|
12
|
function addressfield_devel_generate($object, $field, $instance, $bundle) {
|
13
|
if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_CUSTOM) {
|
14
|
return devel_generate_multiple('_addressfield_devel_generate', $object, $field, $instance, $bundle);
|
15
|
}
|
16
|
else {
|
17
|
return _addressfield_devel_generate($object, $field, $instance, $bundle);
|
18
|
}
|
19
|
}
|
20
|
|
21
|
/*
|
22
|
* Helper function to generate a greeky US-based address
|
23
|
*/
|
24
|
function _addressfield_devel_generate($object, $field, $instance, $bundle) {
|
25
|
// Set default value
|
26
|
$object_field = addressfield_default_values($field, $instance);
|
27
|
$addresses = _addressfield_sample_addresses();
|
28
|
$object_field = array_merge($object_field, $addresses[array_rand($addresses)]);
|
29
|
unset($object_field['data']);
|
30
|
return $object_field;
|
31
|
}
|
32
|
|
33
|
/**
|
34
|
* Returns an array of sample addresses.
|
35
|
*
|
36
|
* @return
|
37
|
* An array of addressfield arrays
|
38
|
*/
|
39
|
function _addressfield_sample_addresses() {
|
40
|
$fields = &drupal_static(__FUNCTION__);
|
41
|
if (!isset($fields)) {
|
42
|
$filepath = DRUPAL_ROOT . '/' . drupal_get_path('module', 'addressfield');
|
43
|
$fields = array();
|
44
|
if ($handle = @fopen("$filepath/addresses.txt", 'r')) {
|
45
|
if (is_resource($handle)) {
|
46
|
while (($buffer = fgets($handle)) !== FALSE) {
|
47
|
list($country, $administrative_area, $sub_administrative_area, $locality, $dependent_locality, $postal_code, $thoroughfare, $premise, $sub_premise) = explode("\t", $buffer);
|
48
|
$fields[] = array(
|
49
|
'country' => ($country == 'NULL') ? NULL : trim($country),
|
50
|
'administrative_area' => ($administrative_area == 'NULL') ? NULL : trim($administrative_area),
|
51
|
'sub_administrative_area' => ($sub_administrative_area == 'NULL') ? NULL : trim($sub_administrative_area),
|
52
|
'locality' => ($locality == 'NULL') ? NULL : trim($locality),
|
53
|
'dependent_locality' => ($dependent_locality == 'NULL') ? NULL : trim($dependent_locality),
|
54
|
'postal_code' => ($postal_code == 'NULL') ? NULL : trim($postal_code),
|
55
|
'thoroughfare' => ($thoroughfare == 'NULL') ? NULL : trim($thoroughfare),
|
56
|
'premise' => ($premise == 'NULL') ? NULL : trim($premise),
|
57
|
'sub_premise' => ($sub_premise == 'NULL') ? NULL : trim($sub_premise),
|
58
|
);
|
59
|
}
|
60
|
}
|
61
|
fclose($handle);
|
62
|
}
|
63
|
}
|
64
|
return $fields;
|
65
|
}
|