You are here

class OgExampleSelectionHandler in Organic groups 7.2

@file OG example selection handler.

Hierarchy

Expanded class hierarchy of OgExampleSelectionHandler

1 string reference to 'OgExampleSelectionHandler'
og_example.inc in og_example/plugins/entityreference/selection/og_example.inc

File

og_example/plugins/entityreference/selection/OgExampleSelectionHandler.class.php, line 9
OG example selection handler.

View source
class OgExampleSelectionHandler extends OgSelectionHandler {

  /**
   * Overrides OgSelectionHandler::getInstance().
   */
  public static function getInstance($field, $instance = NULL, $entity_type = NULL, $entity = NULL) {
    return new OgExampleSelectionHandler($field, $instance, $entity_type, $entity);
  }

  /**
   * Overrides OgSelectionHandler::buildEntityFieldQuery().
   *
   * This is an example of "subgroups" (but without getting into the logic of
   * sub-grouping).
   * The idea here is to show we can set "My groups" and "Other groups" to
   * reference different groups by different
   * logic. In this example, all group nodes below node ID 5, will appear under
   * "My groups", and the rest will appear under "Other groups",
   * for administrators.
   */
  public function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') {
    $group_type = $this->field['settings']['target_type'];
    if (empty($this->instance['field_mode']) || $group_type != 'node') {
      return parent::buildEntityFieldQuery($match, $match_operator);
    }
    $field_mode = $this->instance['field_mode'];
    $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, '=');
    if ($field_mode == 'default') {
      $query
        ->propertyCondition('nid', '5', '<=');
    }
    else {
      $query
        ->propertyCondition('nid', '5', '>');
    }

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

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

}

Members

Namesort descending Modifiers Type Description Overrides
EntityReference_SelectionHandler_Generic::countReferencableEntities public function Implements EntityReferenceHandler::countReferencableEntities(). Overrides EntityReference_SelectionHandler::countReferencableEntities
EntityReference_SelectionHandler_Generic::ensureBaseTable public function Ensure a base table exists for the query.
EntityReference_SelectionHandler_Generic::getLabel public function Implements EntityReferenceHandler::getLabel(). Overrides EntityReference_SelectionHandler::getLabel 1
EntityReference_SelectionHandler_Generic::getReferencableEntities public function Implements EntityReferenceHandler::getReferencableEntities(). Overrides EntityReference_SelectionHandler::getReferencableEntities 1
EntityReference_SelectionHandler_Generic::reAlterQuery protected function Helper method: pass a query to the alteration system again.
EntityReference_SelectionHandler_Generic::validateAutocompleteInput public function Implements EntityReferenceHandler::validateAutocompleteInput(). Overrides EntityReference_SelectionHandler::validateAutocompleteInput
EntityReference_SelectionHandler_Generic::validateReferencableEntities public function Implements EntityReferenceHandler::validateReferencableEntities(). Overrides EntityReference_SelectionHandler::validateReferencableEntities
EntityReference_SelectionHandler_Generic::__construct protected function
OgExampleSelectionHandler::buildEntityFieldQuery public function Overrides OgSelectionHandler::buildEntityFieldQuery(). Overrides OgSelectionHandler::buildEntityFieldQuery
OgExampleSelectionHandler::getInstance public static function Overrides OgSelectionHandler::getInstance(). Overrides OgSelectionHandler::getInstance
OgSelectionHandler::entityFieldQueryAlter public function Implements EntityReferenceHandler::entityFieldQueryAlter(). Overrides EntityReference_SelectionHandler_Generic::entityFieldQueryAlter
OgSelectionHandler::getGidsForCreate private function Get group IDs from URL or OG-context, with access to create group-content.
OgSelectionHandler::settingsForm public static function Override EntityReferenceHandler::settingsForm(). Overrides EntityReference_SelectionHandler_Generic::settingsForm