You are here

function entityreference_current_field_access in Entityreference Current 7

Implements hook_field_access().

File

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

Code

function entityreference_current_field_access($op, $field, $entity_type, $entity, $account) {
  module_load_include('inc', 'entityreference_current');
  if ($op != 'edit' || $field['type'] != 'entityreference') {
    return;
  }
  if (empty($entity)) {

    // $entity might be NULL, so return early.
    // @see field_access().
    return;
  }
  list($id, , $bundle) = entity_extract_ids($entity_type, $entity);
  if ($id) {

    // Entity is already saved.
    return;
  }
  $instance = field_info_instance($entity_type, $field['field_name'], $bundle);
  if (empty($instance['settings']['behaviors']['current']['status'])) {
    return;
  }
  $settings = $instance['settings']['behaviors']['current'];
  if (!empty($settings['skip_perm']) && user_access($settings['skip_perm'])) {
    return;
  }
  $ids = entityreference_current_get_values($field, $instance);
  if (!$ids && $settings['fallback'] == 'hide') {
    return FALSE;
  }
}