You are here

public function Webform::deleteUserData in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Entity/Webform.php \Drupal\webform\Entity\Webform::deleteUserData()

Deletes an item from the webform's user data.

Parameters

string $key: The item name to delete.

Overrides WebformInterface::deleteUserData

File

src/Entity/Webform.php, line 3165

Class

Webform
Defines the webform entity.

Namespace

Drupal\webform\Entity

Code

public function deleteUserData($key) {
  $account = \Drupal::currentUser();

  /** @var \Drupal\user\UserDataInterface $user_data */
  $user_data = \Drupal::service('user.data');
  $values = $user_data
    ->get('webform', $account
    ->id(), $this
    ->id()) ?: [];
  unset($values[$key]);
  $user_data
    ->set('webform', $account
    ->id(), $this
    ->id(), $values);
}