You are here

public function Webform::getUserData in Webform 6.x

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

Returns the stored value for a given key in the webform's user data.

Parameters

string $key: The key of the data to retrieve.

mixed $default: The default value to use if the key is not found.

Return value

mixed The stored value, or NULL if no value exists.

Overrides WebformInterface::getUserData

File

src/Entity/Webform.php, line 3143

Class

Webform
Defines the webform entity.

Namespace

Drupal\webform\Entity

Code

public function getUserData($key, $default = NULL) {
  $account = \Drupal::currentUser();

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