CommerceGuys\Addressing\Formatter\PostalLabelFormatter::buildView PHP Method

buildView() protected method

protected buildView ( CommerceGuys\Addressing\AddressInterface $address, AddressFormat $addressFormat )
$address CommerceGuys\Addressing\AddressInterface
$addressFormat CommerceGuys\Addressing\AddressFormat\AddressFormat
    protected function buildView(AddressInterface $address, AddressFormat $addressFormat)
    {
        $view = parent::buildView($address, $addressFormat);
        // Uppercase fields where required by the format.
        $uppercaseFields = $addressFormat->getUppercaseFields();
        foreach ($uppercaseFields as $uppercaseField) {
            if (isset($view[$uppercaseField])) {
                $view[$uppercaseField]['value'] = mb_strtoupper($view[$uppercaseField]['value'], 'utf-8');
            }
        }
        // Handle international mailing.
        if ($address->getCountryCode() != $this->originCountryCode) {
            // Prefix the postal code.
            $field = AddressField::POSTAL_CODE;
            if (isset($view[$field])) {
                $view[$field]['value'] = $addressFormat->getPostalCodePrefix() . $view[$field]['value'];
            }
            // Universal Postal Union says: "The name of the country of
            // destination shall be written preferably in the language of the
            // country of origin. To avoid any difficulty in the countries of
            // transit, it is desirable for the name of the country of
            // destination to be added in an internationally known language.
            $country = $view['country']['value'];
            $englishCountries = $this->countryRepository->getList('en');
            $englishCountry = $englishCountries[$address->getCountryCode()];
            if ($country != $englishCountry) {
                $country .= ' - ' . $englishCountry;
            }
            $view['country']['value'] = mb_strtoupper($country, 'utf-8');
        } else {
            // The country is not written in case of domestic mailing.
            $view['country']['value'] = '';
        }
        return $view;
    }