public function FeatureContext::alterUserParameters in Open Social 8
Same name and namespace in other branches
- 8.2 tests/behat/features/bootstrap/FeatureContext.php \FeatureContext::alterUserParameters()
Hook into user creation to add profile fields `@afterUserCreate`
@afterUserCreate
File
- tests/
behat/ features/ bootstrap/ FeatureContext.php, line 437
Class
- FeatureContext
- Defines application features from the specific context.
Code
public function alterUserParameters(EntityScope $event) {
$account = $event
->getEntity();
// Get profile of current user.
if (!empty($account->uid)) {
$user_account = \Drupal::entityTypeManager()
->getStorage('user')
->load($account->uid);
$storage = \Drupal::entityTypeManager()
->getStorage('profile');
if (!empty($storage)) {
$user_profile = $storage
->loadByUser($user_account, 'profile', TRUE);
if ($user_profile) {
// Set given profile field values.
foreach ($user_profile
->toArray() as $field_name => $value) {
if (isset($account->{$field_name})) {
$user_profile
->set($field_name, $account->{$field_name});
}
}
$user_profile
->save();
}
}
}
}