You are here

public function WebformEntityReferenceManager::setUserWebformId in Webform 8.5

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

Set user specified webform for a source entity.

Parameters

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

string $webform_id: A webform id.

Overrides WebformEntityReferenceManagerInterface::setUserWebformId

File

src/WebformEntityReferenceManager.php, line 120

Class

WebformEntityReferenceManager
Webform entity reference (field) manager.

Namespace

Drupal\webform

Code

public function setUserWebformId(EntityInterface $entity, $webform_id) {
  $module = 'webform_' . $entity
    ->getEntityTypeId();
  $uid = $this->currentUser
    ->id();
  $name = $entity
    ->id();
  $values = $this->userData
    ->get($module, $uid, $name) ?: [];
  $values['target_id'] = $webform_id;
  $this->userData
    ->set($module, $uid, $name, $values);
}