You are here

function entityreference_prepopulate_field_default_value in Entityreference prepopulate 7

Field default value callback.

Set the default from the URL context. This works even if the widget is not shown, e.g. due to restricted field access.

@todo Check field cardinality.

2 string references to 'entityreference_prepopulate_field_default_value'
entityreference_prepopulate_field_create_instance in ./entityreference_prepopulate.module
Implements hook_field_create_instance().
entityreference_prepopulate_field_update_instance in ./entityreference_prepopulate.module
Implements hook_field_update_instance().

File

./entityreference_prepopulate.module, line 187
Prepopulate entity reference values from URL.

Code

function entityreference_prepopulate_field_default_value($entity_type, $entity, $field, $instance, $langcode) {
  $items = array();
  if ($ids = entityreference_prepopulate_get_values($field, $instance)) {
    $items = array();
    foreach ($ids as $id) {
      $items[] = array(
        'target_id' => $id,
      );
    }
  }
  return $items;
}