class Address in Ubercart 8.4
Defines an object to hold Ubercart mailing address information.
Hierarchy
- class \Drupal\uc_store\Address implements AddressInterface uses StringTranslationTrait, AddressTrait
Expanded class hierarchy of Address
16 files declare their use of Address
- AddressForm.php in shipping/
uc_fulfillment/ src/ Form/ AddressForm.php - AddressPaneBase.php in uc_cart/
src/ Plugin/ Ubercart/ CheckoutPane/ AddressPaneBase.php - AddressTest.php in uc_store/
tests/ src/ Functional/ AddressTest.php - AddressTestTrait.php in uc_store/
tests/ src/ Traits/ AddressTestTrait.php - Check.php in payment/
uc_payment_pack/ src/ Plugin/ Ubercart/ PaymentMethod/ Check.php
2 string references to 'Address'
- AddressPaneBase::review in uc_cart/
src/ Plugin/ Ubercart/ CheckoutPane/ AddressPaneBase.php - Returns the review contents of a checkout pane.
- uc_store_token_info in uc_store/
uc_store.tokens.inc - Implements hook_token_info().
File
- uc_store/
src/ Address.php, line 11
Namespace
Drupal\uc_storeView source
class Address implements AddressInterface {
use AddressTrait;
use StringTranslationTrait;
/**
* Store default country code.
*
* @var string
*/
protected $defaultCountry;
/**
* Constructor.
*
* For convenience, country defaults to store country.
*/
protected function __construct() {
$this->defaultCountry = \Drupal::config('uc_store.settings')
->get('address.country');
$this->country = $this->defaultCountry;
}
/**
* Creates an Address.
*
* @param array $values
* (optional) Array of initialization values.
*
* @return \Drupal\uc_store\AddressInterface
* An Address object.
*/
public static function create(array $values = NULL) {
$address = new Address();
if (isset($values)) {
foreach ($values as $key => $value) {
if (property_exists($address, $key)) {
$address->{$key} = $value;
}
}
}
return $address;
}
/**
* Formats the address for display based on the country's address format.
*
* @return string
* A formatted string containing the address.
*/
public function __toString() {
$variables = [
'!company' => $this->company,
'!first_name' => $this->first_name,
'!last_name' => $this->last_name,
'!street1' => $this->street1,
'!street2' => $this->street2,
'!city' => $this->city,
'!postal_code' => $this->postal_code,
];
$country = $this->country ? \Drupal::service('country_manager')
->getCountry($this->country) : NULL;
if ($country) {
$variables += [
'!zone_code' => $this->zone ?: $this
->t('N/A'),
'!zone_name' => isset($country
->getZones()[$this->zone]) ? $country
->getZones()[$this->zone] : $this
->t('Unknown'),
'!country_name' => $this
->t($country
->getName()),
'!country_code2' => $country
->id(),
'!country_code3' => $country
->getAlpha3(),
];
if ($this->country != $this->defaultCountry) {
$variables['!country_name_if'] = $variables['!country_name'];
$variables['!country_code2_if'] = $variables['!country_code2'];
$variables['!country_code3_if'] = $variables['!country_code3'];
}
else {
$variables['!country_name_if'] = '';
$variables['!country_code2_if'] = '';
$variables['!country_code3_if'] = '';
}
$format = implode("\n", $country
->getAddressFormat());
}
else {
$format = "!company\n!first_name !last_name\n!street1\n!street2\n!city\n!postal_code";
}
$address = Html::escape(strtr($format, $variables));
// Remove empty lines in the middle of an address string (0 or more
// whitespace characters bracketed by \n) then remove (trim) whitespace
// from the beginning and end of the string.
$address = trim(preg_replace("/\n\\s*\n/", "\n", $address));
if (\Drupal::config('uc_store.settings')
->get('capitalize_address')) {
$address = mb_strtoupper($address);
}
// <br> instead of <br />, because Twig will change it to <br> anyway and
// it's nice to be able to test the Raw output.
return nl2br($address, FALSE);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Address:: |
protected | property | Store default country code. | |
Address:: |
public static | function | Creates an Address. | |
Address:: |
protected | function | Constructor. | |
Address:: |
public | function | Formats the address for display based on the country's address format. | |
AddressTrait:: |
public | property | City name. | |
AddressTrait:: |
public | property | Company or organization. | |
AddressTrait:: |
public | property | ISO 3166-1 2-character numeric country code. | |
AddressTrait:: |
public | property | Email address. | |
AddressTrait:: |
public | property | Given name. | |
AddressTrait:: |
protected | property | The unique address identifier. | |
AddressTrait:: |
protected | property | The human-readable nickname of the location. | |
AddressTrait:: |
public | property | Surname. | |
AddressTrait:: |
public | property | Telephone number. | |
AddressTrait:: |
public | property | Postal code. | |
AddressTrait:: |
public | property | First line of street address. | |
AddressTrait:: |
public | property | Second line of street address. | |
AddressTrait:: |
public | property | State, provence, or region id. | |
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public static | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
AddressTrait:: |
public | function | ||
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |