You are here

protected function SynonymsFieldItemList::computeValue in Synonyms 2.0.x

Computes the values for an item list.

Overrides ComputedItemListTrait::computeValue

File

modules/synonyms_list_field/src/Field/SynonymsFieldItemList.php, line 18

Class

SynonymsFieldItemList
Field item list of "synonyms" computed base field.

Namespace

Drupal\synonyms_list_field\Field

Code

protected function computeValue() {
  $entity = $this
    ->getEntity();
  $delta = 0;

  // This prepends the entity label to synonyms list if the
  // 'Include entity label' checkbox is checked in settings.
  if (\Drupal::config('synonyms_list_field.settings')
    ->get('include_entity_label')) {
    $this->list[$delta] = $this
      ->createItem($delta, $entity
      ->label());
    $delta++;
  }
  foreach (\Drupal::service('synonyms.provider_service')
    ->getEntitySynonyms($entity) as $synonym) {
    $this->list[$delta] = $this
      ->createItem($delta, $synonym);
    $delta++;
  }
}