Loading src/Entity/Profile.php +6 −3 Original line number Diff line number Diff line Loading @@ -259,8 +259,11 @@ class Profile extends EditorialContentEntityBase implements ProfileInterface { if (!$this->isPublished()) { $this->setDefault(FALSE); } // Mark the profile as default if there's no other default. if ($this->getOwnerId() && $this->isPublished() && !$this->isDefault()) { // Mark the profile as default if it's being owned by existing // non-anonymous user and there's no other default. if ($this->getOwner() && $this->isPublished() && !$this->isDefault()) { $profile = $storage->loadByUser($this->getOwner(), $this->bundle()); if (!$profile || !$profile->isDefault()) { $this->setDefault(TRUE); Loading @@ -283,7 +286,7 @@ class Profile extends EditorialContentEntityBase implements ProfileInterface { if ($this->getOwnerId()) { $default = $this->isDefault(); $original_default = $this->original ? $this->original->isDefault() : FALSE; if ($default && !$original_default) { if ($default && !$original_default && $this->getOwner()) { // The profile was set as default, remove the flag from other profiles. $profiles = $storage->loadMultipleByUser($this->getOwner(), $this->bundle()); foreach ($profiles as $profile) { Loading tests/src/Kernel/ProfileTest.php +12 −0 Original line number Diff line number Diff line Loading @@ -303,6 +303,18 @@ class ProfileTest extends EntityKernelTestBase { // Confirm that re-saving the other published profile sets it as default. $profile1->save(); $this->assertTrue($profile1->isDefault()); // Confirm that profile may be still saved, even if it references // non-existing user. /** @var \Drupal\profile\Entity\ProfileInterface $profile1 */ $profile3 = Profile::create([ 'type' => $profile_type->id(), 'uid' => $this->user2->id() + 100, ]); $profile3->save(); // Confirm that the profile was not set as default. $this->assertFalse($profile3->isDefault()); } /** Loading Loading
src/Entity/Profile.php +6 −3 Original line number Diff line number Diff line Loading @@ -259,8 +259,11 @@ class Profile extends EditorialContentEntityBase implements ProfileInterface { if (!$this->isPublished()) { $this->setDefault(FALSE); } // Mark the profile as default if there's no other default. if ($this->getOwnerId() && $this->isPublished() && !$this->isDefault()) { // Mark the profile as default if it's being owned by existing // non-anonymous user and there's no other default. if ($this->getOwner() && $this->isPublished() && !$this->isDefault()) { $profile = $storage->loadByUser($this->getOwner(), $this->bundle()); if (!$profile || !$profile->isDefault()) { $this->setDefault(TRUE); Loading @@ -283,7 +286,7 @@ class Profile extends EditorialContentEntityBase implements ProfileInterface { if ($this->getOwnerId()) { $default = $this->isDefault(); $original_default = $this->original ? $this->original->isDefault() : FALSE; if ($default && !$original_default) { if ($default && !$original_default && $this->getOwner()) { // The profile was set as default, remove the flag from other profiles. $profiles = $storage->loadMultipleByUser($this->getOwner(), $this->bundle()); foreach ($profiles as $profile) { Loading
tests/src/Kernel/ProfileTest.php +12 −0 Original line number Diff line number Diff line Loading @@ -303,6 +303,18 @@ class ProfileTest extends EntityKernelTestBase { // Confirm that re-saving the other published profile sets it as default. $profile1->save(); $this->assertTrue($profile1->isDefault()); // Confirm that profile may be still saved, even if it references // non-existing user. /** @var \Drupal\profile\Entity\ProfileInterface $profile1 */ $profile3 = Profile::create([ 'type' => $profile_type->id(), 'uid' => $this->user2->id() + 100, ]); $profile3->save(); // Confirm that the profile was not set as default. $this->assertFalse($profile3->isDefault()); } /** Loading