entityreference.devel_generate.inc 980 B

12345678910111213141516171819202122232425262728
  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. foreach ($referencable_entity as $type => $eids) {
  21. $object_field['target_id'] = array_rand($eids);
  22. }
  23. }
  24. return $object_field;
  25. }