Commit acedd509 authored by Keerthana Sengundhar's avatar Keerthana Sengundhar Committed by Jonathan Sacksick
Browse files

Issue #3080025 by abramm, neelam_wadhwani, AjitS, keerthana13, bojanz,...

Issue #3080025 by abramm, neelam_wadhwani, AjitS, keerthana13, bojanz, jsacksick: Check if user exists in profile preSave().
parent 115ff352
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -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);
@@ -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) {
+12 −0
Original line number Diff line number Diff line
@@ -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());

  }

  /**