randomMachineName(); $label = !empty($label) ? $label : $this->randomMachineName(); $type = ProfileType::create([ 'id' => $id, 'label' => $label, 'registration' => $registration, 'roles' => $roles, ]); $type->save(); return $type; } /** * Create a user, and optionally a profile. * * @param \Drupal\profile\Entity\ProfileTypeInterface $profile_type * A profile type for the created profile entity. * @param \Drupal\user\UserInterface $user * A user to create a profile. * * @return \Drupal\profile\Entity\ProfileInterface * A profile for a user. */ protected function createProfile(ProfileTypeInterface $profile_type, UserInterface $user) { $profile = Profile::create([ 'type' => $profile_type->id(), 'uid' => $user->id(), ]); $profile->save(); return $profile; } }