modules/acm/src/ACMAddressFormatter.php
protected function getValues($address, $country_code, AddressFormat $address_format) {
    $values = [];
    $values['title'] = isset($address->title) ? $address->title : '';
    $values['givenName'] = isset($address->firstname) ? $address->firstname : '';
    $values['familyName'] = isset($address->lastname) ? $address->lastname : '';
    $values['organization'] = isset($address->organization) ? $address->organization : '';
    $values['addressLine1'] = isset($address->street) ? $address->street : '';
    $values['addressLine2'] = isset($address->street2) ? $address->street2 : '';
    $values['postalCode'] = isset($address->postcode) ? $address->postcode : '';
    $values['administrativeArea'] = isset($address->region) ? $address->region : '';
    $values['locality'] = isset($address->city) ? $address->city : '';
    $values['dependentLocality'] = isset($address->dependent_locality) ? $address->dependent_locality : '';

    $original_values = [];
    $subdivision_fields = $address_format->getUsedSubdivisionFields();
    $parents = [];
    foreach ($subdivision_fields as $index => $field) {
      if (empty($values[$field])) {
        // This level is empty, so there can be no sublevels.
        break;
      }
      $parents[] = $index ? $original_values[$subdivision_fields[$index - 1]] : $address->country_id;
      $subdivision_repository = \Drupal::service('address.subdivision_repository');
      $subdivision = $subdivision_repository->get($values[$field], $parents);
      if (!$subdivision) {
        break;
      }

      // Remember the original value so that it can be used for $parents.
      $original_values[$field] = $values[$field];
      // Replace the value with the expected code.
      $use_local_name = Locale::match('en', $subdivision->getLocale());
      $values[$field] = $use_local_name ? $subdivision->getLocalCode() : $subdivision->getCode();
      if (!$subdivision->hasChildren()) {
        // The current subdivision has no children, stop.
        break;
      }
    }

    return $values;
  }
protected function getValues($address, $country_code, AddressFormat $address_format) {
    $values = [];
    $values['title'] = isset($address->title) ? $address->title : '';
    $values['givenName'] = isset($address->firstname) ? $address->firstname : '';
    $values['familyName'] = isset($address->lastname) ? $address->lastname : '';
    $values['organization'] = isset($address->organization) ? $address->organization : '';
    $values['addressLine1'] = isset($address->street) ? $address->street : '';
    $values['addressLine2'] = isset($address->street2) ? $address->street2 : '';
    $values['postalCode'] = isset($address->postcode) ? $address->postcode : '';
    $values['administrativeArea'] = isset($address->region) ? $address->region : '';
    $values['locality'] = isset($address->city) ? $address->city : '';
    $values['dependentLocality'] = isset($address->dependent_locality) ? $address->dependent_locality : '';

    $original_values = [];
    $subdivision_fields = $address_format->getUsedSubdivisionFields();
    $parents = [];
    foreach ($subdivision_fields as $index => $field) {
      if (empty($values[$field])) {
        // This level is empty, so there can be no sublevels.
        break;
      }
      $parents[] = $index ? $original_values[$subdivision_fields[$index - 1]] : $address->country_id;
      $subdivision_repository = \Drupal::service('address.subdivision_repository');
      $subdivision = $subdivision_repository->get($values[$field], $parents);
      if (!$subdivision) {
        break;
      }

      // Remember the original value so that it can be used for $parents.
      $original_values[$field] = $values[$field];
      // Replace the value with the expected code.
      $use_local_name = Locale::match('en', $subdivision->getLocale());
      $values[$field] = $use_local_name ? $subdivision->getLocalCode() : $subdivision->getCode();
      if (!$subdivision->hasChildren()) {
        // The current subdivision has no children, stop.
        break;
      }
    }

    return $values;
  }
protected function getValues ( $ address , $ country_code , AddressFormat $ address_format ) { $ values = [ ] ; $ values [ 'title' ] = isset ( $ address -> title ) ? $ address -> title : '' ; $ values [ 'givenName' ] = isset ( $ address -> firstname ) ? $ address -> firstname : '' ; $ values [ 'familyName' ] = isset ( $ address -> lastname ) ? $ address -> lastname : '' ; $ values [ 'organization' ] = isset ( $ address -> organization ) ? $ address -> organization : '' ; $ values [ 'addressLine1' ] = isset ( $ address -> street ) ? $ address -> street : '' ; $ values [ 'addressLine2' ] = isset ( $ address -> street2 ) ? $ address -> street2 : '' ; $ values [ 'postalCode' ] = isset ( $ address -> postcode ) ? $ address -> postcode : '' ; $ values [ 'administrativeArea' ] = isset ( $ address -> region ) ? $ address -> region : '' ; $ values [ 'locality' ] = isset ( $ address -> city ) ? $ address -> city : '' ; $ values [ 'dependentLocality' ] = isset ( $ address -> dependent_locality ) ? $ address -> dependent_locality : '' ; $ original_values = [ ] ; $ subdivision_fields = $ address_format -> getUsedSubdivisionFields ( ) ; $ parents = [ ] ; foreach ( $ subdivision_fields as $ index => $ field ) { if ( empty ( $ values [ $ field ] ) ) { // This level is empty, so there can be no sublevels. break ; } $ parents [ ] = $ index ? $ original_values [ $ subdivision_fields [ $ index - 1 ] ] : $ address -> country_id ; $ subdivision_repository = \ Drupal :: service ( 'address.subdivision_repository' ) ; $ subdivision = $ subdivision_repository -> get ( $ values [ $ field ] , $ parents ) ; if ( ! $ subdivision ) { break ; } // Remember the original value so that it can be used for $parents. $ original_values [ $ field ] = $ values [ $ field ] ; // Replace the value with the expected code. $ use_local_name = Locale :: match ( 'en' , $ subdivision -> getLocale ( ) ) ; $ values [ $ field ] = $ use_local_name ? $ subdivision -> getLocalCode ( ) : $ subdivision -> getCode ( ) ; if ( ! $ subdivision -> hasChildren ( ) ) { // The current subdivision has no children, stop. break ; } } return $ values ; }
Gets the address values used for rendering.

@param object $address
The address.
@param string $country_code
The country code.
@param \CommerceGuys\Addressing\AddressFormat\AddressFormat $address_format
The address format.

@return array
The values, keyed by address field.
Gets the address values used for rendering .