ThesaurusRefComputed.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Drupal\materio_sapi;
  3. use Drupal\Core\Field\EntityReferenceFieldItemList;
  4. use Drupal\Core\TypedData\ComputedItemListTrait;
  5. class ThesaurusRefComputed extends EntityReferenceFieldItemList {
  6. use ComputedItemListTrait;
  7. /**
  8. * Computed related blog posts.
  9. */
  10. protected function computeValue() {
  11. $field_name = $this->getName();
  12. switch ($field_name) {
  13. case 'thesaurus_0':
  14. $delta = 0;
  15. break;
  16. case 'thesaurus_1':
  17. $delta = 1;
  18. break;
  19. case 'thesaurus_2':
  20. $delta = 2;
  21. break;
  22. case 'thesaurus_3':
  23. $delta = 3;
  24. break;
  25. case 'thesaurus_4':
  26. $delta = 4;
  27. break;
  28. default:
  29. $delta = -1;
  30. break;
  31. }
  32. $thes_terms = $this->getParent()->getValue()->get('field_thesaurus')->getValue();
  33. if (count($thes_terms) > 0) {
  34. if (isset($thes_terms[$delta])) {
  35. $term = $thes_terms[$delta];
  36. $this->list[0] = $this->createItem(0, $term);
  37. $t="t";
  38. }
  39. }
  40. }
  41. }