public function Authmap::save in External Authentication 8
Same name and namespace in other branches
- 2.0.x src/Authmap.php \Drupal\externalauth\Authmap::save()
Save an external authname for a given Drupal user.
Parameters
\Drupal\user\UserInterface $account: The Drupal user account.
string $provider: The name of the service providing external authentication.
string $authname: The unique, external authentication name provided by authentication provider.
mixed $data: Optional extra (serialized) data to store with the authname.
Overrides AuthmapInterface::save
File
- src/
Authmap.php, line 35
Class
- Authmap
- Class Authmap.
Namespace
Drupal\externalauthCode
public function save(UserInterface $account, $provider, $authname, $data = NULL) {
if (!is_scalar($data)) {
$data = serialize($data);
}
// If a mapping (for the same provider) from this authname to a different
// account already exists, this throws an exception. If a mapping (for the
// same provider) to this account already exists, the currently stored
// authname is overwritten.
$this->connection
->merge('authmap')
->keys([
'uid' => $account
->id(),
'provider' => $provider,
])
->fields([
'authname' => $authname,
'data' => $data,
])
->execute();
}