protected function AddressBook::isAvailable in Commerce Core 8.2
Checks if the given profile is available.
If the list of available countries is restricted, the profile address is checked against it.
Parameters
\Drupal\profile\Entity\ProfileInterface $profile: The profile.
array $available_countries: List of country codes. If empty, all countries will be available.
Return value
bool TRUE if the profile is available, FALSE otherwise.
2 calls to AddressBook::isAvailable()
- AddressBook::load in modules/
order/ src/ AddressBook.php - Loads the customer's profile.
- AddressBook::loadAll in modules/
order/ src/ AddressBook.php - Loads all profiles for the given customer.
File
- modules/
order/ src/ AddressBook.php, line 182
Class
Namespace
Drupal\commerce_orderCode
protected function isAvailable(ProfileInterface $profile, array $available_countries) {
if (empty($available_countries)) {
return TRUE;
}
/** @var \Drupal\address\Plugin\Field\FieldType\AddressItem $address */
$address = $profile
->get('address')
->first();
$country_code = $address ? $address
->getCountryCode() : 'ZZ';
return in_array($country_code, $available_countries);
}