1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Support for processing entity reference fields in devel generate.
|
6
|
*/
|
7
|
|
8
|
function entityreference_devel_generate($object, $field, $instance, $bundle) {
|
9
|
if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_CUSTOM) {
|
10
|
return devel_generate_multiple('_entityreference_devel_generate', $object, $field, $instance, $bundle);
|
11
|
}
|
12
|
else {
|
13
|
return _entityreference_devel_generate($object, $field, $instance, $bundle);
|
14
|
}
|
15
|
}
|
16
|
|
17
|
function _entityreference_devel_generate($object, $field, $instance, $bundle) {
|
18
|
$object_field = array();
|
19
|
// Get all the entity that are referencable here.
|
20
|
$referencable_entity = entityreference_get_selection_handler($field, $instance)->getReferencableEntities();
|
21
|
if (is_array($referencable_entity) && !empty($referencable_entity)) {
|
22
|
// $referencable_entity is keyed by bundle type.
|
23
|
$random_bundle = array_rand($referencable_entity);
|
24
|
if (!empty($random_bundle)) {
|
25
|
$target_id = array_rand($referencable_entity[$random_bundle]);
|
26
|
if (!empty($referencable_entity[$random_bundle][$target_id])) {
|
27
|
$object_field['target_id'] = $target_id;
|
28
|
}
|
29
|
}
|
30
|
}
|
31
|
return $object_field;
|
32
|
}
|