48 lines
1.0 KiB
PHP
48 lines
1.0 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Drupal\materio_sapi;
|
||
|
|
||
|
use Drupal\Core\Field\EntityReferenceFieldItemList;
|
||
|
use Drupal\Core\TypedData\ComputedItemListTrait;
|
||
|
|
||
|
class ThesaurusRefComputed extends EntityReferenceFieldItemList {
|
||
|
use ComputedItemListTrait;
|
||
|
|
||
|
/**
|
||
|
* Computed related blog posts.
|
||
|
*/
|
||
|
protected function computeValue() {
|
||
|
$field_name = $this->getName();
|
||
|
switch ($field_name) {
|
||
|
case 'thesaurus_0':
|
||
|
$delta = 0;
|
||
|
break;
|
||
|
case 'thesaurus_1':
|
||
|
$delta = 1;
|
||
|
break;
|
||
|
case 'thesaurus_2':
|
||
|
$delta = 2;
|
||
|
break;
|
||
|
case 'thesaurus_3':
|
||
|
$delta = 3;
|
||
|
break;
|
||
|
case 'thesaurus_4':
|
||
|
$delta = 4;
|
||
|
break;
|
||
|
default:
|
||
|
$delta = -1;
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
$thes_terms = $this->getParent()->getValue()->get('field_thesaurus')->getValue();
|
||
|
|
||
|
if (count($thes_terms) > 0) {
|
||
|
if (isset($thes_terms[$delta])) {
|
||
|
$term = $thes_terms[$delta];
|
||
|
$this->list[0] = $this->createItem(0, $term);
|
||
|
$t="t";
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|