-
Notifications
You must be signed in to change notification settings - Fork 0
/
properties.devel_generate.inc
45 lines (39 loc) · 1.1 KB
/
properties.devel_generate.inc
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
<?php
// $Id$
/**
* @file
* Contains devel_generate hook implementation to fill properties fields.
*/
/**
* Implements hook_devel_generate().
*/
function properties_devel_generate($object, $field, $instance, $bundle) {
static $categories = NULL;
if (!isset($categories)) {
$categories = properties_category_load_multiple(array_keys(properties_category_load_paging(50)));
}
$items = array();
$max = rand(0, min(array(count($categories), 5)));
$cweight = 0;
for ($i = 0; $i < $max; $i++) {
// Make sure the category is not yet selected.
do {
$category = $categories[array_rand($categories)];
} while (isset($items[$category->name]));
$items[$category->name] = array(
'_weight' => $cweight++,
);
$aweight = 0;
foreach ($category->attributes as $attribute) {
$items[$category->name]['properties'][$attribute->name] = array(
'category' => $category->name,
'attribute' => $attribute->name,
'value' => devel_generate_word(10),
'_weight' => $aweight++,
);
}
}
if (count($items)) {
return array(0 => $items);
}
}