getCurrentLanguage()->getId(); $elements = []; foreach ($items as $delta => $item) { // return nothing if target_id is null if(!$item->target_id) return; $term = Term::load($item->target_id); // translate the term $term = \Drupal::service('entity.repository')->getTranslationFromContext($term, $language); $elements[$delta] = [ // We create a render array to produce the desired markup, // "

The color code ... #hexcolor

". // See theme_html_tag(). '#type' => 'html_tag', '#tag' => 'p', '#value' => $this->t('@target : @location', [ '@target' => $term->getName(), '@location' => $item->location ] ), ]; } return $elements; } }