From ac6b9565335342fd1a7b99ff5350d553005e3480 Mon Sep 17 00:00:00 2001
From: jochemvn <jochem@goalgorilla.com>
Date: Fri, 18 Aug 2017 15:46:17 +0200
Subject: [PATCH] 2900630 by jochemvn: Prevent a uer form having two profiles,
 if profile fields are already asked during registration

---
 .../social_profile/social_profile.module                | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/modules/social_features/social_profile/social_profile.module b/modules/social_features/social_profile/social_profile.module
index 4ec6ac309..09b28551b 100644
--- a/modules/social_features/social_profile/social_profile.module
+++ b/modules/social_features/social_profile/social_profile.module
@@ -233,11 +233,18 @@ function social_profile_user_insert(UserInterface $account) {
   // If the new account has a UID, we can create a default profile.
   // Default image is added through the field settings.
   if (!empty($account->id())) {
-    $profile = Profile::create($expected = [
-      'type' => ProfileType::load('profile')->id(),
-      'uid' => $account->id(),
-    ]);
-    $profile->save();
+    /** @var ProfileType $profile_type */
+    $profile_type = ProfileType::load('profile');
+    // Sometimes profile fields are already requested during registrataion.
+    // In those cases, the profile will already be created from that.
+    if ($profile_type->getRegistration() === FALSE) {
+      // Create a profile.
+      $profile = Profile::create($expected = [
+        'type' => $profile_type->id(),
+        'uid' => $account->id(),
+      ]);
+      $profile->save();
+    }
   }
 }
 
