You are here

public function OgCommonsSelectionHandler::buildEntityFieldQuery in Drupal Commons 7.3

Overrides OgSelectionHandler::buildEntityFieldQuery().

Overrides OgSelectionHandler::buildEntityFieldQuery

File

modules/commons/commons_groups/plugins/entityreference/selection/OgCommonsSelectionHandler.class.php, line 17
OG Commons groups selection handler.

Class

OgCommonsSelectionHandler
@file OG Commons groups selection handler.

Code

public function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') {
  $group_type = $this->field['settings']['target_type'];
  if (empty($this->instance['field_mode']) || $group_type != 'node' || user_is_anonymous()) {
    return parent::buildEntityFieldQuery($match, $match_operator);
  }
  $handler = EntityReference_SelectionHandler_Generic::getInstance($this->field, $this->instance, $this->entity_type, $this->entity);
  $query = $handler
    ->buildEntityFieldQuery($match, $match_operator);

  // Show only the entities that are active groups.
  $query
    ->fieldCondition(OG_GROUP_FIELD, 'value', 1);
  $query
    ->fieldCondition('field_og_subscribe_settings', 'value', 'anyone');

  // Add this property to make sure we will have the {node} table later on in
  // OgCommonsSelectionHandler::entityFieldQueryAlter().
  $query
    ->propertyCondition('nid', 0, '>');
  $query
    ->addMetaData('entityreference_selection_handler', $this);

  // FIXME: http://drupal.org/node/1325628
  unset($query->tags['node_access']);
  $query
    ->addTag('entity_field_access');
  $query
    ->addTag('og');
  return $query;
}