countryManager = $country_manager; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( $plugin_id, $plugin_definition, $configuration['field_definition'], $configuration['settings'], $configuration['label'], $configuration['view_mode'], $configuration['third_party_settings'], $container->get('country_manager') ); } /** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $language) { $elements = []; foreach ($items as $delta => $item) { foreach (['country', 'locality', 'thoroughfare', 'postal_code'] as $key) { $value = $item->$key; // Replace the country code with the country name. if ($key === 'country') { $countries = $this->countryManager->getList(); $value = !empty($countries[$value]) ? $countries[$value] : ''; } $elements[$delta][$key] = [ '#type' => 'html_tag', '#tag' => 'p', '#value' => $value, ]; } } return $elements; } }