modules/acm/src/ACMAddressFormatter.php
protected function viewElement($address, $langcode) {
    $country_code = $address->country_id;
    $country_repository = \Drupal::service('address.country_repository');
    $countries = $country_repository->getList();
    $address_format_repository = \Drupal::service('address.address_format_repository');
    $address_format = $address_format_repository->get($country_code);
    $values = $this->getValues($address, $country_code, $address_format);

    $element = [];
    $element['address_format'] = [
      '#type' => 'value',
      '#value' => $address_format,
    ];
    // TODO get the locale from the i18n helper.
    $element['locale'] = [
      '#type' => 'value',
      '#value' => 'en',
    ];
    $element['country_code'] = [
      '#type' => 'value',
      '#value' => $country_code,
    ];
    $element['country'] = [
      '#type' => 'html_tag',
      '#tag' => 'span',
      '#attributes' => ['class' => ['country']],
      '#value' => Html::escape($countries[$country_code]),
      '#placeholder' => '%country',
    ];
    foreach ($address_format->getUsedFields() as $field) {
      $property = FieldHelper::getPropertyName($field);
      $class = str_replace('_', '-', $property);

      $element[$property] = [
        '#type' => 'html_tag',
        '#tag' => 'span',
        '#attributes' => ['class' => [$class]],
        '#value' => $values[$field],
        '#placeholder' => '%' . $field,
      ];
    }

    $element['title'] = [
      '#type' => 'html_tag',
      '#tag' => 'span',
      '#attributes' => ['class' => ['title']],
      '#value' => $values['title'],
      '#placeholder' => '%title',
    ];

    return $element;
  }
protected function viewElement($address, $langcode) {
    $country_code = $address->country_id;
    $country_repository = \Drupal::service('address.country_repository');
    $countries = $country_repository->getList();
    $address_format_repository = \Drupal::service('address.address_format_repository');
    $address_format = $address_format_repository->get($country_code);
    $values = $this->getValues($address, $country_code, $address_format);

    $element = [];
    $element['address_format'] = [
      '#type' => 'value',
      '#value' => $address_format,
    ];
    // TODO get the locale from the i18n helper.
    $element['locale'] = [
      '#type' => 'value',
      '#value' => 'en',
    ];
    $element['country_code'] = [
      '#type' => 'value',
      '#value' => $country_code,
    ];
    $element['country'] = [
      '#type' => 'html_tag',
      '#tag' => 'span',
      '#attributes' => ['class' => ['country']],
      '#value' => Html::escape($countries[$country_code]),
      '#placeholder' => '%country',
    ];
    foreach ($address_format->getUsedFields() as $field) {
      $property = FieldHelper::getPropertyName($field);
      $class = str_replace('_', '-', $property);

      $element[$property] = [
        '#type' => 'html_tag',
        '#tag' => 'span',
        '#attributes' => ['class' => [$class]],
        '#value' => $values[$field],
        '#placeholder' => '%' . $field,
      ];
    }

    $element['title'] = [
      '#type' => 'html_tag',
      '#tag' => 'span',
      '#attributes' => ['class' => ['title']],
      '#value' => $values['title'],
      '#placeholder' => '%title',
    ];

    return $element;
  }
protected function viewElement ( $ address , $ langcode ) { $ country_code = $ address -> country_id ; $ country_repository = \ Drupal :: service ( 'address.country_repository' ) ; $ countries = $ country_repository -> getList ( ) ; $ address_format_repository = \ Drupal :: service ( 'address.address_format_repository' ) ; $ address_format = $ address_format_repository -> get ( $ country_code ) ; $ values = $ this -> getValues ( $ address , $ country_code , $ address_format ) ; $ element = [ ] ; $ element [ 'address_format' ] = [ '#type' => 'value' , '#value' => $ address_format , ] ; // TODO get the locale from the i18n helper. $ element [ 'locale' ] = [ '#type' => 'value' , '#value' => 'en' , ] ; $ element [ 'country_code' ] = [ '#type' => 'value' , '#value' => $ country_code , ] ; $ element [ 'country' ] = [ '#type' => 'html_tag' , '#tag' => 'span' , '#attributes' => [ 'class' => [ 'country' ] ] , '#value' => Html :: escape ( $ countries [ $ country_code ] ) , '#placeholder' => '%country' , ] ; foreach ( $ address_format -> getUsedFields ( ) as $ field ) { $ property = FieldHelper :: getPropertyName ( $ field ) ; $ class = str_replace ( '_' , '-' , $ property ) ; $ element [ $ property ] = [ '#type' => 'html_tag' , '#tag' => 'span' , '#attributes' => [ 'class' => [ $ class ] ] , '#value' => $ values [ $ field ] , '#placeholder' => '%' . $ field , ] ; } $ element [ 'title' ] = [ '#type' => 'html_tag' , '#tag' => 'span' , '#attributes' => [ 'class' => [ 'title' ] ] , '#value' => $ values [ 'title' ] , '#placeholder' => '%title' , ] ; return $ element ; }
Builds a renderable array for a single address item.

@param object $address
The address.
@param string $langcode
The language that should be used to render the field.

@return array
A renderable array.
Builds a renderable array for a single address item .