function AllExceptHostEntity::buildEntityQuery

Same name in other branches
  1. 10 core/modules/system/tests/modules/entity_reference_test/src/Plugin/EntityReferenceSelection/AllExceptHostEntity.php \Drupal\entity_reference_test\Plugin\EntityReferenceSelection\AllExceptHostEntity::buildEntityQuery()

Overrides DefaultSelection::buildEntityQuery

File

core/modules/system/tests/modules/entity_reference_test/src/Plugin/EntityReferenceSelection/AllExceptHostEntity.php, line 25

Class

AllExceptHostEntity
Allows access to all entities except for the host entity.

Namespace

Drupal\entity_reference_test\Plugin\EntityReferenceSelection

Code

protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
    $query = parent::buildEntityQuery($match, $match_operator);
    
    /** @var \Drupal\Core\Entity\EntityInterface $entity */
    if ($entity = $this->configuration['entity']) {
        $target_type = $this->configuration['target_type'];
        $entity_type = $this->entityTypeManager
            ->getDefinition($target_type);
        $query->condition($entity_type->getKey('id'), $entity->id(), '<>');
    }
    return $query;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.