-
Notifications
You must be signed in to change notification settings - Fork 0
/
page_section.devel_generate.inc
54 lines (46 loc) · 1.35 KB
/
page_section.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
46
47
48
49
50
51
52
53
54
<?php
/**
* @file
* Provides the Devel Generate integration for Page Section.
*/
/**
* Implements hook_devel_generate().
*/
function page_section_devel_generate($object, $field, $instance, $bundle) {
if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_CUSTOM) {
$object_field = array();
switch ($field['cardinality']) {
case FIELD_CARDINALITY_UNLIMITED:
// Just an arbitrary number for 'unlimited'.
$max = rand(3, 8);
break;
default:
$max = $field['cardinality'] - 1;
break;
}
for ($i = 0; $i <= $max; $i++) {
$result = _page_section_devel_generate($object, $field, $instance, $bundle);
if (!empty($result)) {
$object_field[$i] = $result;
}
}
return $object_field;
}
else {
return _page_section_devel_generate($object, $field, $instance, $bundle);
}
}
/**
* Internal function to generate a single page section and field item.
*/
function _page_section_devel_generate($object, $field, $instance, $bundle) {
$types = page_section_type_info();
if (empty($types)) {
return NULL;
}
$type = array_rand($types);
$page_section = page_section_create(array('type' => $type));
devel_generate_fields($page_section, 'page_section', $type);
page_section_save($page_section);
return array('sid' => $page_section->sid);
}