You are here

public function WebformEntityReferenceManager::getUserWebformId in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/WebformEntityReferenceManager.php \Drupal\webform\WebformEntityReferenceManager::getUserWebformId()

Get user specified webform for a source entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: A fieldable content entity.

Return value

string|null A webform id or NULL.

Overrides WebformEntityReferenceManagerInterface::getUserWebformId

1 call to WebformEntityReferenceManager::getUserWebformId()
WebformEntityReferenceManager::getWebform in src/WebformEntityReferenceManager.php
Get an entity's target webform.

File

src/WebformEntityReferenceManager.php, line 135

Class

WebformEntityReferenceManager
Webform entity reference (field) manager.

Namespace

Drupal\webform

Code

public function getUserWebformId(EntityInterface $entity) {
  $module = 'webform_' . $entity
    ->getEntityTypeId();
  $uid = $this->currentUser
    ->id();
  $name = $entity
    ->id();
  $values = $this->userData
    ->get($module, $uid, $name) ?: [];
  if (isset($values['target_id'])) {
    $webforms = $this
      ->getWebforms($entity);
    if (isset($webforms[$values['target_id']])) {
      return $values['target_id'];
    }
  }
  return NULL;
}