UserData::set

public UserData::set($module, $uid, $name, $value)

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 80

Class

UserData
Defines the user data service.

Namespace

Drupal\user

Code

public function set($module, $uid, $name, $value) {
  $serialized = 0;
  if (!is_scalar($value)) {
    $value = serialize($value);
    $serialized = 1;
  }
  $this->connection->merge('users_data')
    ->keys(array(
      'uid' => $uid,
      'module' => $module,
      'name' => $name,
    ))
    ->fields(array(
      'value' => $value,
      'serialized' => $serialized,
    ))
    ->execute();
}
doc_Drupal
2016-10-29 09:52:29
Comments
Leave a Comment

Please login to continue.