You are here

function entityreference_current_field_default_value in Entityreference Current 7

Field default value callback.

Set the default from the Menu Object 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_current_field_default_value'
entityreference_current_field_create_instance in ./entityreference_current.module
Implements hook_field_create_instance().
entityreference_current_field_update_instance in ./entityreference_current.module
Implements hook_field_update_instance().

File

./entityreference_current.module, line 172
Prepoplates entity reference values from Current Entity(Menu Object).

Code

function entityreference_current_field_default_value($entity_type, $entity, $field, $instance, $langcode) {
  module_load_include('inc', 'entityreference_current');
  $items = array();
  if ($ids = entityreference_current_get_values($field, $instance)) {
    $items = array();
    foreach ($ids as $id) {
      $items[] = array(
        'target_id' => $id,
      );
    }
  }
  return $items;
}