public function FeatureContext::alterUserParameters in Open Social 8.4
Same name and namespace in other branches
- 8.9 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
- 8.3 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
- 8.5 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
- 8.6 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
- 8.7 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
- 8.8 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
- 10.3.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
- 10.0.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
- 10.1.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
- 10.2.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
Hook into user creation to add profile fields `@afterUserCreate`
@afterUserCreate
File
- tests/
behat/ features/ bootstrap/ FeatureContext.php, line 492
Class
- FeatureContext
- Defines application features from the specific context.
Namespace
Drupal\social\BehatCode
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();
}
}
}
}