Commit 8b9b61b9 authored by bojanz's avatar bojanz

Issue #3077908 followup: Rename AddressBook::loadDefault to AddressBook::load

parent 5a736a92
......@@ -107,7 +107,7 @@ class AddressBook implements AddressBookInterface {
/**
* {@inheritdoc}
*/
public function loadDefault(UserInterface $customer, $profile_type_id, array $available_countries = []) {
public function load(UserInterface $customer, $profile_type_id, array $available_countries = []) {
if ($customer->isAnonymous()) {
return NULL;
}
......
......@@ -75,10 +75,13 @@ interface AddressBookInterface {
public function loadAll(UserInterface $customer, $profile_type_id, array $available_countries = []);
/**
* Loads the customer's default profile.
* Loads the customer's profile.
*
* If no default profile is found, falls back
* to the newest published profile.
* Takes the default profile, if found.
* Otherwise falls back to the newest published profile.
*
* Primarily used for profile types which only allow a
* single profile per user.
*
* Ensures that the loaded profile is available, by filtering it
* against $available_countries. If the loaded profile is not
......@@ -92,9 +95,9 @@ interface AddressBookInterface {
* List of country codes. If empty, all countries will be available.
*
* @return \Drupal\profile\Entity\ProfileInterface|null
* The default profile, or NULL if none found.
* The profile, or NULL if none found.
*/
public function loadDefault(UserInterface $customer, $profile_type_id, array $available_countries = []);
public function load(UserInterface $customer, $profile_type_id, array $available_countries = []);
/**
* Checks if the profile needs to be copied to the customer's address book.
......
......@@ -145,7 +145,7 @@ class AddressBookController implements ContainerInjectionInterface {
$profiles = $this->addressBook->loadAll($user, $profile_type_id);
}
else {
$profile = $this->addressBook->loadDefault($user, $profile_type_id);
$profile = $this->addressBook->load($user, $profile_type_id);
$profiles = [];
if ($profile) {
$profiles[$profile->id()] = $profile;
......@@ -255,7 +255,7 @@ class AddressBookController implements ContainerInjectionInterface {
// Deny access when the profile type only allows a single profile
// per user, and such a profile already exists.
if (!$profile_type->allowsMultiple()) {
$profile = $this->addressBook->loadDefault($user, $profile_type->id());
$profile = $this->addressBook->load($user, $profile_type->id());
// The result is marked as non-cacheable because profiles change
// too often for the result to be cached based on their list tag.
$other_result = AccessResult::allowedIf(empty($profile))->mergeCacheMaxAge(0);
......
......@@ -212,7 +212,7 @@ class CustomerProfile extends EntityInlineFormBase {
// A single address book profile is allowed.
// The customer profile form is being rendered for the first time.
// Use the default profile to pre-fill the profile form.
$address_book_profile = $this->addressBook->loadDefault($customer, $profile_type_id, $available_countries);
$address_book_profile = $this->addressBook->load($customer, $profile_type_id, $available_countries);
}
// Copy field values from the address book profile to the actual profile.
......
......@@ -162,7 +162,7 @@ class AddressBookTest extends CommerceKernelTestBase {
/**
* @covers ::loadAll
* @covers ::loadDefault
* @covers ::load
*/
public function testLoadProfiles() {
$second_profile = Profile::create([
......@@ -184,8 +184,8 @@ class AddressBookTest extends CommerceKernelTestBase {
$this->assertEquals([1 => $this->defaultProfile], $this->addressBook->loadAll($this->user, 'customer', ['US']));
$this->assertEquals([3 => $second_profile], $this->addressBook->loadAll($this->user, 'customer', ['RS']));
$this->assertEquals($this->defaultProfile, $this->addressBook->loadDefault($this->user, 'customer'));
$this->assertNull($this->addressBook->loadDefault($this->user, 'customer', ['RS']));
$this->assertEquals($this->defaultProfile, $this->addressBook->load($this->user, 'customer'));
$this->assertNull($this->addressBook->load($this->user, 'customer', ['RS']));
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment