You are here

function commons_groups_entityreference_default_value in Drupal Commons 7.3

Default value function for the og_group_ref reference field. This function is assigned to the field with the default_value_function property defined in our instances of the og_group_ref field, which takes place in commons_groups_field_definition().

2 string references to 'commons_groups_entityreference_default_value'
commons_groups_field_definition in modules/commons/commons_groups/commons_groups.features.field_instance.inc
commons_trusted_contacts_field_definition_group in modules/commons/commons_trusted_contacts/commons_trusted_contacts.features.field_instance.inc

File

modules/commons/commons_groups/commons_groups.module, line 691

Code

function commons_groups_entityreference_default_value($entity_type, $entity, $field, $instance, $langcode) {
  $items = array();
  $field_name = $field['field_name'];
  if (empty($_GET[$field_name]) || !is_string($_GET[$field_name])) {
    return $items;
  }
  if (empty($instance['settings']['behaviors']['prepopulate']['status'])) {
    return $items;
  }
  $ids = explode(',', $_GET[$field_name]);

  // Check access to the provided entities.
  $target_type = $field['settings']['target_type'];
  entity_load($target_type, $ids);

  // Remove group nodes hidden by the node access system.
  foreach ($ids as $target_id) {
    $target = entity_load_single($target_type, $target_id);
    if (entity_access('view', $target_type, $target) && og_is_group_type($target_type, $target->type) && (og_user_access($target_type, $target_id, "create {$entity->type} content") || og_user_access($target_type, $target_id, "update any {$entity->type} content"))) {
      $items[] = array(
        'target_id' => $target_id,
      );
    }
  }
  return $items;
}