public function profileGetAddressFieldValue($field_name, $address_element, ProfileInterface $user_profile = NULL) {
    if ($user_profile === NULL) {
      return '';
    }

    $value = '';
    try {
      $address = $user_profile->get($field_name)->getValue();
      if (isset($address['0'][$address_element])) {
        $value = $address['0'][$address_element];
      }
    }
    catch (\Exception $e) {
      $value = '';
    }
    return $value;
  }
public function profileGetAddressFieldValue($field_name, $address_element, ProfileInterface $user_profile = NULL) {
    if ($user_profile === NULL) {
      return '';
    }

    $value = '';
    try {
      $address = $user_profile->get($field_name)->getValue();
      if (isset($address['0'][$address_element])) {
        $value = $address['0'][$address_element];
      }
    }
    catch (\Exception $e) {
      $value = '';
    }
    return $value;
  }
public function profileGetAddressFieldValue ( $ field_name , $ address_element , ProfileInterface $ user_profile = NULL ) { if ( $ user_profile === NULL ) { return '' ; } $ value = '' ; try { $ address = $ user_profile -> get ( $ field_name ) -> getValue ( ) ; if ( isset ( $ address [ '0' ] [ $ address_element ] ) ) { $ value = $ address [ '0' ] [ $ address_element ] ; } } catch ( \ Exception $ e ) { $ value = '' ; } return $ value ; }
Returns the value for the address field and element within address.

@param string $field_name
The field name to get the value for.
@param string $address_element
The address element to get the value for, e.g. 'country_code'.
@param \Drupal\profile\Entity\ProfileInterface $user_profile
The profile to get the data for.

@return string
Returns the value of the address element for the profile.
Returns the value for the address field and element within address .