protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
    $configuration = $this->getConfiguration();
    $target_type = $configuration['target_type'];
    $entity_type = $this->entityManager->getDefinition($target_type);

    $query = $this->entityManager->getStorage($target_type)->getQuery();

    // If 'target_bundles_no_dep' is NULL, all bundles are referenceable, no further
    // conditions are needed.
    if (is_array($configuration['target_bundles_no_dep'])) {
      // If 'target_bundles_no_dep' is an empty array, no bundle is referenceable,
      // force the query to never return anything and bail out early.
      if ($configuration['target_bundles_no_dep'] === []) {
        $query->condition($entity_type->getKey('id'), NULL, '=');
        return $query;
      }
      else {
        $query->condition($entity_type->getKey('bundle'), $configuration['target_bundles_no_dep'], 'IN');
      }
    }

    if (isset($match) && $label_key = $entity_type->getKey('label')) {
      $query->condition($label_key, $match, $match_operator);
    }

    // Add entity-access tag.
    $query->addTag($target_type . '_access');

    // Add the Selection handler for system_query_entity_reference_alter().
    $query->addTag('entity_reference');
    $query->addMetaData('entity_reference_selection_handler', $this);

    // Add the sort option.
    if ($configuration['sort']['field'] !== '_none') {
      $query->sort($configuration['sort']['field'], $configuration['sort']['direction']);
    }

    return $query;
  }
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
    $configuration = $this->getConfiguration();
    $target_type = $configuration['target_type'];
    $entity_type = $this->entityManager->getDefinition($target_type);

    $query = $this->entityManager->getStorage($target_type)->getQuery();

    // If 'target_bundles_no_dep' is NULL, all bundles are referenceable, no further
    // conditions are needed.
    if (is_array($configuration['target_bundles_no_dep'])) {
      // If 'target_bundles_no_dep' is an empty array, no bundle is referenceable,
      // force the query to never return anything and bail out early.
      if ($configuration['target_bundles_no_dep'] === []) {
        $query->condition($entity_type->getKey('id'), NULL, '=');
        return $query;
      }
      else {
        $query->condition($entity_type->getKey('bundle'), $configuration['target_bundles_no_dep'], 'IN');
      }
    }

    if (isset($match) && $label_key = $entity_type->getKey('label')) {
      $query->condition($label_key, $match, $match_operator);
    }

    // Add entity-access tag.
    $query->addTag($target_type . '_access');

    // Add the Selection handler for system_query_entity_reference_alter().
    $query->addTag('entity_reference');
    $query->addMetaData('entity_reference_selection_handler', $this);

    // Add the sort option.
    if ($configuration['sort']['field'] !== '_none') {
      $query->sort($configuration['sort']['field'], $configuration['sort']['direction']);
    }

    return $query;
  }
protected function buildEntityQuery ( $ match = NULL , $ match_operator = 'CONTAINS' ) { $ configuration = $ this -> getConfiguration ( ) ; $ target_type = $ configuration [ 'target_type' ] ; $ entity_type = $ this -> entityManager -> getDefinition ( $ target_type ) ; $ query = $ this -> entityManager -> getStorage ( $ target_type ) -> getQuery ( ) ; // If 'target_bundles_no_dep' is NULL, all bundles are referenceable, no further // conditions are needed. if ( is_array ( $ configuration [ 'target_bundles_no_dep' ] ) ) { // If 'target_bundles_no_dep' is an empty array, no bundle is referenceable, // force the query to never return anything and bail out early. if ( $ configuration [ 'target_bundles_no_dep' ] === [ ] ) { $ query -> condition ( $ entity_type -> getKey ( 'id' ) , NULL , '=' ) ; return $ query ; } else { $ query -> condition ( $ entity_type -> getKey ( 'bundle' ) , $ configuration [ 'target_bundles_no_dep' ] , 'IN' ) ; } } if ( isset ( $ match ) && $ label_key = $ entity_type -> getKey ( 'label' ) ) { $ query -> condition ( $ label_key , $ match , $ match_operator ) ; } // Add entity-access tag. $ query -> addTag ( $ target_type . '_access' ) ; // Add the Selection handler for system_query_entity_reference_alter(). $ query -> addTag ( 'entity_reference' ) ; $ query -> addMetaData ( 'entity_reference_selection_handler' , $ this ) ; // Add the sort option. if ( $ configuration [ 'sort' ] [ 'field' ] !== '_none' ) { $ query -> sort ( $ configuration [ 'sort' ] [ 'field' ] , $ configuration [ 'sort' ] [ 'direction' ] ) ; } return $ query ; }
Builds an EntityQuery to get referenceable entities.

@param string|null $match
(Optional) Text to match the label against. Defaults to NULL.
@param string $match_operator
(Optional) The operation the matching should be done with. Defaults
to "CONTAINS".

@return \Drupal\Core\Entity\Query\QueryInterface
The EntityQuery object with the basic conditions and sorting applied to
it.
Builds an EntityQuery to get referenceable entities .