You are here

public function WebformEntityReferenceManager::getWebform in Webform 6.x

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

Get an entity's target webform.

Parameters

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

Return value

\Drupal\webform\WebformInterface|null The entity's target webform or NULL.

Overrides WebformEntityReferenceManagerInterface::getWebform

File

src/WebformEntityReferenceManager.php, line 215

Class

WebformEntityReferenceManager
Webform entity reference (field) manager.

Namespace

Drupal\webform

Code

public function getWebform(EntityInterface $entity = NULL) {
  if ($webform_id = $this
    ->getUserWebformId($entity)) {
    return Webform::load($webform_id);
  }
  elseif ($webforms = $this
    ->getWebforms($entity)) {
    return reset($webforms);
  }
  else {
    return NULL;
  }
}