public function UserData::set in Drupal 9
Same name and namespace in other branches
- 8 core/modules/user/src/UserData.php \Drupal\user\UserData::set()
Stores data for a user account.
Parameters
string $module: The name of the module the data is associated with.
int $uid: The user account ID the data is associated with.
string $name: The name of the data key.
mixed $value: The value to store. Non-scalar values are serialized automatically.
Overrides UserDataInterface::set
File
- core/
modules/ user/ src/ UserData.php, line 76
Class
- UserData
- Defines the user data service.
Namespace
Drupal\userCode
public function set($module, $uid, $name, $value) {
$serialized = (int) (!is_scalar($value));
if ($serialized) {
$value = serialize($value);
}
$this->connection
->merge('users_data')
->keys([
'uid' => $uid,
'module' => $module,
'name' => $name,
])
->fields([
'value' => $value,
'serialized' => $serialized,
])
->execute();
}