added country name to sapi index
This commit is contained in:
29
web/modules/custom/materio_sapi/src/CountryNameComputed.php
Normal file
29
web/modules/custom/materio_sapi/src/CountryNameComputed.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\materio_sapi;
|
||||
|
||||
use Drupal\Core\Field\FieldItemList;
|
||||
use Drupal\Core\TypedData\ComputedItemListTrait;
|
||||
|
||||
class CountryNameComputed extends FieldItemList {
|
||||
use ComputedItemListTrait;
|
||||
|
||||
protected function computeValue() {
|
||||
$term = $this->getEntity();
|
||||
$name = $term->getName();
|
||||
$address = $term->get('field_public_address')->first();
|
||||
if ($address) {
|
||||
$country_code = $address->getCountryCode();
|
||||
if ($country_code) {
|
||||
$full_country_list = \Drupal::service('country_manager')->getList();
|
||||
$country_name = $full_country_list[$country_code];
|
||||
$lang = \Drupal::languageManager()->getCurrentLanguage()->getId();
|
||||
$translated_markup = $country_name->render();
|
||||
if($parent->id() == 5719){
|
||||
$t="t";
|
||||
}
|
||||
$this->list[0] = $this->createItem(0, $translated_markup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user