CountryNameComputed.php 878 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace Drupal\materio_sapi;
  3. use Drupal\Core\Field\FieldItemList;
  4. use Drupal\Core\TypedData\ComputedItemListTrait;
  5. class CountryNameComputed extends FieldItemList {
  6. use ComputedItemListTrait;
  7. protected function computeValue() {
  8. $term = $this->getEntity();
  9. $name = $term->getName();
  10. $address = $term->get('field_public_address')->first();
  11. if ($address) {
  12. $country_code = $address->getCountryCode();
  13. if ($country_code) {
  14. $full_country_list = \Drupal::service('country_manager')->getList();
  15. $country_name = $full_country_list[$country_code];
  16. $lang = \Drupal::languageManager()->getCurrentLanguage()->getId();
  17. $translated_markup = $country_name->render();
  18. if($parent->id() == 5719){
  19. $t="t";
  20. }
  21. $this->list[0] = $this->createItem(0, $translated_markup);
  22. }
  23. }
  24. }
  25. }