function UserData::set

Same name in other branches
  1. 9 core/modules/user/src/UserData.php \Drupal\user\UserData::set()
  2. 10 core/modules/user/src/UserData.php \Drupal\user\UserData::set()
  3. 11.x core/modules/user/src/UserData.php \Drupal\user\UserData::set()

Overrides UserDataInterface::set

File

core/modules/user/src/UserData.php, line 76

Class

UserData
Defines the user data service.

Namespace

Drupal\user

Code

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.