You are here

public function UserData::delete in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/user/src/UserData.php \Drupal\user\UserData::delete()

Deletes data stored for a user account.

Parameters

string|array $module: (optional) The name of the module the data is associated with. Can also be an array to delete the data of multiple modules.

int|array $uid: (optional) The user account ID the data is associated with. If omitted, all data for $module is deleted. Can also be an array of IDs to delete the data of multiple user accounts.

string $name: (optional) The name of the data key. If omitted, all data associated with $module and $uid is deleted.

Overrides UserDataInterface::delete

File

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

Class

UserData
Defines the user data service.

Namespace

Drupal\user

Code

public function delete($module = NULL, $uid = NULL, $name = NULL) {
  $query = $this->connection
    ->delete('users_data');

  // Cast scalars to array so we can consistently use an IN condition.
  if (isset($module)) {
    $query
      ->condition('module', (array) $module, 'IN');
  }
  if (isset($uid)) {
    $query
      ->condition('uid', (array) $uid, 'IN');
  }
  if (isset($name)) {
    $query
      ->condition('name', (array) $name, 'IN');
  }
  $query
    ->execute();
}