function social_profile_user_insert in Open Social 8.5
Same name and namespace in other branches
- 8.9 modules/social_features/social_profile/social_profile.module \social_profile_user_insert()
- 8 modules/social_features/social_profile/social_profile.module \social_profile_user_insert()
- 8.2 modules/social_features/social_profile/social_profile.module \social_profile_user_insert()
- 8.3 modules/social_features/social_profile/social_profile.module \social_profile_user_insert()
- 8.4 modules/social_features/social_profile/social_profile.module \social_profile_user_insert()
- 8.6 modules/social_features/social_profile/social_profile.module \social_profile_user_insert()
- 8.7 modules/social_features/social_profile/social_profile.module \social_profile_user_insert()
- 8.8 modules/social_features/social_profile/social_profile.module \social_profile_user_insert()
- 10.3.x modules/social_features/social_profile/social_profile.module \social_profile_user_insert()
- 10.0.x modules/social_features/social_profile/social_profile.module \social_profile_user_insert()
- 10.1.x modules/social_features/social_profile/social_profile.module \social_profile_user_insert()
- 10.2.x modules/social_features/social_profile/social_profile.module \social_profile_user_insert()
Implements hook_ENTITY_TYPE_insert().
In order to save a new default profile on user creation.
File
- modules/
social_features/ social_profile/ social_profile.module, line 414 - The Social profile module.
Code
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())) {
/** @var \Drupal\profile\Entity\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) {
$default_values = [
'type' => $profile_type
->id(),
'uid' => $account
->id(),
];
// Get all field instances for the profile entity and check if the address
// field exists.
$instances = \Drupal::service('entity_field.manager')
->getFieldDefinitions('profile', $profile_type
->id());
if (array_key_exists('field_profile_address', $instances)) {
// Set the users default country to the site default country.
$default_values['field_profile_address'][0]['country_code'] = \Drupal::config('system.date')
->get('country.default');
}
// Create a profile.
$profile = Profile::create($default_values);
$profile
->save();
}
}
}