1 |
85ad3d82
|
Assos Assos
|
<?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 |
|
|
// Get a random key.
|
23 |
|
|
foreach ($referencable_entity as $type => $eids) {
|
24 |
|
|
$object_field['target_id'] = array_rand($eids);
|
25 |
|
|
}
|
26 |
|
|
}
|
27 |
|
|
return $object_field;
|
28 |
|
|
} |