You are here

SynonymsFieldItemList.php in Synonyms 8

File

src/Plugin/SynonymsFieldItemList.php
View source
<?php

namespace Drupal\synonyms\Plugin;

use Drupal\Core\Field\FieldItemList;

/**
 * Field item list of "synonyms" computed base field.
 */
class SynonymsFieldItemList extends FieldItemList {

  /**
   * {@inheritdoc}
   */
  public function getValue($include_computed = FALSE) {
    $synonyms = [];
    $entity = $this
      ->getEntity();
    $behavior_service = \Drupal::getContainer()
      ->get('synonyms.behaviors');
    $services = $behavior_service
      ->getBehaviorServices();
    foreach ($services as $service_id => $service) {
      foreach ($behavior_service
        ->getSynonymConfigEntities($service_id, $entity
        ->getEntityTypeId(), $entity
        ->bundle()) as $synonym_config) {
        $synonyms = array_merge($synonyms, $synonym_config
          ->getProviderPluginInstance()
          ->getSynonyms($entity));
      }
    }
    return array_unique($synonyms);
  }

}

Classes

Namesort descending Description
SynonymsFieldItemList Field item list of "synonyms" computed base field.