You are here

protected function SelectionBase::buildEntityFieldQuery in Entity reference 8

Build an EntityFieldQuery to get referencable entities.

4 calls to SelectionBase::buildEntityFieldQuery()
SelectionBase::countReferencableEntities in lib/Drupal/entityreference/Plugin/entityreference/selection/SelectionBase.php
Implements EntityReferenceHandler::countReferencableEntities().
SelectionBase::getReferencableEntities in lib/Drupal/entityreference/Plugin/entityreference/selection/SelectionBase.php
Implements EntityReferenceHandler::getReferencableEntities().
SelectionBase::validateReferencableEntities in lib/Drupal/entityreference/Plugin/entityreference/selection/SelectionBase.php
Implements EntityReferenceHandler::validateReferencableEntities().
SelectionEntityTypeUser::buildEntityFieldQuery in lib/Drupal/entityreference/Plugin/Type/Selection/SelectionEntityTypeUser.php
Build an EntityFieldQuery to get referencable entities.
1 method overrides SelectionBase::buildEntityFieldQuery()
SelectionEntityTypeUser::buildEntityFieldQuery in lib/Drupal/entityreference/Plugin/Type/Selection/SelectionEntityTypeUser.php
Build an EntityFieldQuery to get referencable entities.

File

lib/Drupal/entityreference/Plugin/entityreference/selection/SelectionBase.php, line 241
Definition of Drupal\entityreference\Plugin\entityreference\selection\SelectionBase.

Class

SelectionBase
Plugin implementation of the 'selection' entityreference.

Namespace

Drupal\entityreference\Plugin\entityreference\selection

Code

protected function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') {
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', $this->field['settings']['target_type']);
  if (!empty($this->field['settings']['handler_settings']['target_bundles'])) {
    $query
      ->entityCondition('bundle', $this->field['settings']['handler_settings']['target_bundles'], 'IN');
  }
  if (isset($match)) {
    $entity_info = entity_get_info($this->field['settings']['target_type']);
    if (isset($entity_info['entity keys']['label'])) {
      $query
        ->propertyCondition($entity_info['entity keys']['label'], $match, $match_operator);
    }
  }

  // Add a generic entity access tag to the query.
  $query
    ->addTag($this->field['settings']['target_type'] . '_access');
  $query
    ->addTag('entityreference');
  $query
    ->addMetaData('field', $this->field);
  $query
    ->addMetaData('entityreference_selection_handler', $this);

  // Add the sort option.
  if (!empty($this->field['settings']['handler_settings']['sort'])) {
    $sort_settings = $this->field['settings']['handler_settings']['sort'];
    if ($sort_settings['type'] == 'property') {
      $query
        ->propertyOrderBy($sort_settings['property'], $sort_settings['direction']);
    }
    elseif ($sort_settings['type'] == 'field') {
      list($field, $column) = explode(':', $sort_settings['field'], 2);
      $query
        ->fieldOrderBy($field, $column, $sort_settings['direction']);
    }
  }
  return $query;
}