public function WebformSubmissionStorage::loadFromToken in Webform 8.5
Same name and namespace in other branches
- 6.x src/WebformSubmissionStorage.php \Drupal\webform\WebformSubmissionStorage::loadFromToken()
 
Load submission using webform (secure) token.
Parameters
string $token: The submission (secure) token.
\Drupal\webform\WebformInterface $webform: The webform that the submission token is associated with.
\Drupal\Core\Entity\EntityInterface|null $source_entity: (optional) A webform submission source entity.
\Drupal\Core\Session\AccountInterface|null $account: (optional) A user account.
Return value
\Drupal\webform\WebformSubmissionInterface|null A webform submission.
Overrides WebformSubmissionStorageInterface::loadFromToken
File
- src/
WebformSubmissionStorage.php, line 193  
Class
- WebformSubmissionStorage
 - Defines the webform submission storage.
 
Namespace
Drupal\webformCode
public function loadFromToken($token, WebformInterface $webform, EntityInterface $source_entity = NULL, AccountInterface $account = NULL) {
  // Check token.
  if (!$token) {
    return NULL;
  }
  // Check that (secure) tokens are enabled for the webform.
  if (!$account && !$webform
    ->getSetting('token_update')) {
    return NULL;
  }
  // Attempt to load the submission using the token.
  $properties = [
    'token' => $token,
  ];
  // Add optional source entity to properties.
  if ($source_entity) {
    $properties['entity_type'] = $source_entity
      ->getEntityTypeId();
    $properties['entity_id'] = $source_entity
      ->id();
  }
  // Add optional user account to properties.
  if ($account) {
    $properties['uid'] = $account
      ->id();
  }
  $entities = $this
    ->loadByProperties($properties);
  if (empty($entities)) {
    return NULL;
  }
  /** @var \Drupal\webform\WebformSubmissionInterface $entity */
  $entity = reset($entities);
  // Make sure the submission is associated with the webform.
  if ($entity
    ->getWebform()
    ->id() !== $webform
    ->id()) {
    return NULL;
  }
  return $entity;
}