You are here

trait SynonymsGetTrait in Synonyms 8

Trait to extract synonyms from an entity.

Hierarchy

3 files declare their use of SynonymsGetTrait
BaseField.php in src/Plugin/Synonyms/Provider/BaseField.php
EntityReferenceField.php in src/Plugin/Synonyms/Provider/EntityReferenceField.php
Field.php in src/Plugin/Synonyms/Provider/Field.php

File

src/SynonymsProviderInterface/SynonymsGetTrait.php, line 10

Namespace

Drupal\synonyms\SynonymsProviderInterface
View source
trait SynonymsGetTrait {

  /**
   * Fetch synonyms from multiple entities at once.
   *
   * @param array $entities
   *   Array of entities whose synonyms should be fetched. They array will be
   *   keyed by entity ID and all provided entities will be of the same entity
   *   type and bundle.
   *
   * @return array
   *   Array of extracted synonyms. It must be keyed by entity ID and each sub
   *   array should represent a list of synonyms that were extracted from the
   *   corresponding entity
   */
  public function getSynonymsMultiple(array $entities) {
    $synonyms = [];
    foreach ($entities as $entity_id => $entity) {
      $synonyms[$entity_id] = $this
        ->getSynonyms($entity);
    }
    return $synonyms;
  }

  /**
   * Fetch synonyms from an entity.
   *
   * @param Drupal\Core\Entity\ContentEntityInterface $entity
   *   Entity whose synonyms should be fetched.
   *
   * @return string[]
   *   Array of extracted synonyms
   */
  public abstract function getSynonyms(ContentEntityInterface $entity);

}

Members

Namesort descending Modifiers Type Description Overrides
SynonymsGetTrait::getSynonyms abstract public function Fetch synonyms from an entity. 3
SynonymsGetTrait::getSynonymsMultiple public function Fetch synonyms from multiple entities at once.