You are here

public function ProviderService::getSynonymConfigEntities in Synonyms 2.0.x

Get a list of enabled synonym providers.

Parameters

string $entity_type: Entity type for which to conduct the search.

string|array $bundle: Single bundle or an array of them for which to conduct the search. If null is given, then no restrictions are applied on bundle level.

Return value

\Drupal\synonyms\Entity\Synonym[] The array of enabled synonym providers

2 calls to ProviderService::getSynonymConfigEntities()
ProviderService::findSynonyms in src/SynonymsService/ProviderService.php
Lookup entity IDs by the $condition.
ProviderService::getEntitySynonyms in src/SynonymsService/ProviderService.php
Retrieve a list of entity synonyms.

File

src/SynonymsService/ProviderService.php, line 81

Class

ProviderService
A collection of handy provider-related methods.

Namespace

Drupal\synonyms\SynonymsService

Code

public function getSynonymConfigEntities($entity_type, $bundle) {
  $entities = [];
  if (is_scalar($bundle) && !is_null($bundle)) {
    $bundle = [
      $bundle,
    ];
  }
  foreach ($this->entityTypeManager
    ->getStorage('synonym')
    ->loadMultiple() as $synonym_config) {
    $provider_instance = $synonym_config
      ->getProviderPluginInstance();
    $provider_definition = $provider_instance
      ->getPluginDefinition();
    if ($provider_definition['controlled_entity_type'] == $entity_type && (!is_array($bundle) || in_array($provider_definition['controlled_bundle'], $bundle))) {
      $entities[] = $synonym_config;
    }
  }
  return $entities;
}