You are here

public function BehaviorService::getSynonymConfigEntities in Synonyms 8

Get a list of enabled synonym providers for a requested synonyms behavior.

Parameters

string $synonyms_behavior: ID of the synonyms behavior services whose enabled providers should be returned.

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

File

src/SynonymsService/BehaviorService.php, line 107

Class

BehaviorService
Collect all known synonyms behavior services.

Namespace

Drupal\synonyms\SynonymsService

Code

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