You are here

public function Webform::hasUserData in Webform 8.5

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

Determine if the stored value for a given key exists in the webform's user data.

Parameters

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

Return value

bool TRUE if the stored value for a given key exists.

Overrides WebformInterface::hasUserData

File

src/Entity/Webform.php, line 3177

Class

Webform
Defines the webform entity.

Namespace

Drupal\webform\Entity

Code

public function hasUserData($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()) ?: [];
  return isset($values[$key]) ? TRUE : FALSE;
}