You are here

public function WebformRequest::isValidSourceEntity in Webform 8.5

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

Check if a source entity is attached to a webform.

Parameters

\Drupal\Core\Entity\EntityInterface $webform_entity: A webform or webform submission.

\Drupal\Core\Entity\EntityInterface|null $source_entity: A webform submission's source entity.

Return value

bool TRUE if a webform is attached to a webform submission source entity.

Overrides WebformRequestInterface::isValidSourceEntity

2 calls to WebformRequest::isValidSourceEntity()
WebformRequest::getBaseRouteName in src/WebformRequest.php
Get the base route name for a form/submission and source entity.
WebformRequest::getRouteParameters in src/WebformRequest.php
Get the route parameters for a form/submission and source entity.

File

src/WebformRequest.php, line 317

Class

WebformRequest
Handles webform requests.

Namespace

Drupal\webform

Code

public function isValidSourceEntity(EntityInterface $webform_entity, EntityInterface $source_entity = NULL) {

  // Validate that source entity exists and can be linked to.
  if (!$source_entity || !$source_entity
    ->hasLinkTemplate('canonical')) {
    return FALSE;
  }

  // Get the webform.
  if ($webform_entity instanceof WebformSubmissionInterface) {
    $webform = $webform_entity
      ->getWebform();
  }
  elseif ($webform_entity instanceof WebformInterface) {
    $webform = $webform_entity;
  }
  else {
    throw new \InvalidArgumentException('Webform entity');
  }

  // Validate that source entity's field target id is the correct webform.
  $webform_target = $this->webformEntityReferenceManager
    ->getWebform($source_entity);
  if ($webform_target && $webform_target
    ->id() === $webform
    ->id()) {
    return TRUE;
  }
  else {
    return FALSE;
  }
}