You are here

public function ProviderService::findSynonyms in Synonyms 2.0.x

Lookup entity IDs by the $condition.

Parameters

\Drupal\Core\Database\Query\Condition $condition: Condition which defines what to search for.

\Drupal\Core\Entity\EntityTypeInterface $entity_type: Entity type within which to search.

string|array $bundle: Either single bundle string or array of such within which to search. NULL stands for no filtering by bundle, i.e. searching among all bundles.

Return value

array Array of looked up synonyms/entities. Each element in this array will be an object with the following structure:

  • synonym: (string) synonym that was looked up
  • entity_id: (int) ID of the entity which this synonym belongs to
1 call to ProviderService::findSynonyms()
ProviderService::getBySynonym in src/SynonymsService/ProviderService.php
Try finding entities by their name or synonym.

File

src/SynonymsService/ProviderService.php, line 116

Class

ProviderService
A collection of handy provider-related methods.

Namespace

Drupal\synonyms\SynonymsService

Code

public function findSynonyms(Condition $condition, EntityTypeInterface $entity_type, $bundle = NULL) {
  if (!$entity_type
    ->getKey('bundle')) {
    $bundle = $entity_type
      ->id();
  }
  $lookup = [];
  if (is_null($bundle)) {
    $bundle = array_keys($this->entityTypeBundleInfo
      ->getBundleInfo($entity_type
      ->id()));
  }
  foreach ($this
    ->getSynonymConfigEntities($entity_type
    ->id(), $bundle) as $synonym_config) {
    foreach ($synonym_config
      ->getProviderPluginInstance()
      ->synonymsFind(clone $condition) as $synonym) {
      $lookup[] = $synonym;
    }
  }
  return $lookup;
}