You are here

class EntityReference_SelectionHandler_Generic_party in Party 7

Same name and namespace in other branches
  1. 8.2 includes/entityreference/party.entityreference.inc \EntityReference_SelectionHandler_Generic_party

Entity Selection Handler class for Party Entities

Hierarchy

Expanded class hierarchy of EntityReference_SelectionHandler_Generic_party

File

includes/entityreference/party.entityreference.inc, line 10
A entity reference selection handler class to allow us to make use of advance party features such as hats.

View source
class EntityReference_SelectionHandler_Generic_party extends EntityReference_SelectionHandler_Generic {

  /**
   * Add a "target hats" field to the Entity field query.
   */
  public static function settingsForm($field, $instance) {
    $form = parent::settingsForm($field, $instance);

    // If party_hat is enabled allow filtering by them.
    if (module_exists('party_hat')) {
      $hats = entity_load('party_hat');
      $options = array();
      foreach ($hats as $hat) {
        $options[$hat->name] = $hat->label;
      }
      $form['target_hats'] = array(
        '#type' => 'select',
        '#title' => t('Target hats'),
        '#options' => $options,
        '#default_value' => isset($field['settings']['handler_settings']['target_hats']) ? $field['settings']['handler_settings']['target_hats'] : array(),
        '#size' => 6,
        '#multiple' => TRUE,
        '#description' => t('The hats that can be referenced. Optional, leave empty for all hats.'),
      );
    }
    else {
      $form['target_hats'] = array(
        '#type' => 'value',
        '#value' => array(),
      );
    }

    // If party_user is enabled allow filtering by parties thaat have a user
    if (module_exists('party_user')) {

      // @todo: Implement. EFQ doesn't let you do joins. So we may have to be clever.
    }
    return $form;
  }

  /**
   * Add a field condition to the EntityFieldQuery to limit by hats.
   */
  protected function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') {
    $query = parent::buildEntityFieldQuery($match, $match_operator);

    // If party_hat is enabled filter by them
    if (module_exists('party_hat') && !empty($this->field['settings']['handler_settings']['target_hats'])) {
      $query
        ->fieldCondition('party_hat', 'hat_name', $this->field['settings']['handler_settings']['target_hats'], 'IN');
    }
    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::entityFieldQueryAlter public function Implements EntityReferenceHandler::entityFieldQueryAlter(). Overrides EntityReference_SelectionHandler::entityFieldQueryAlter 5
EntityReference_SelectionHandler_Generic::getInstance public static function Implements EntityReferenceHandler::getInstance(). Overrides EntityReference_SelectionHandler::getInstance
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
EntityReference_SelectionHandler_Generic_party::buildEntityFieldQuery protected function Add a field condition to the EntityFieldQuery to limit by hats. Overrides EntityReference_SelectionHandler_Generic::buildEntityFieldQuery
EntityReference_SelectionHandler_Generic_party::settingsForm public static function Add a "target hats" field to the Entity field query. Overrides EntityReference_SelectionHandler_Generic::settingsForm