You are here

public function FeatureContext::alterUserParameters in Open Social 8.4

Same name and namespace in other branches
  1. 8.9 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
  2. 8.3 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
  3. 8.5 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
  4. 8.6 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
  5. 8.7 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
  6. 8.8 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
  7. 10.3.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
  8. 10.0.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
  9. 10.1.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::alterUserParameters()
  10. 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\Behat

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();
      }
    }
  }
}