entityreference.devel_generate.inc 932 B

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