You are here

public function WebformRevisionsRequest::isValidSourceEntity in Config Entity Revisions 1.x

Same name and namespace in other branches
  1. 8.2 modules/webform_revisions/src/WebformRevisionsRequest.php \Drupal\webform_revisions\WebformRevisionsRequest::isValidSourceEntity()
  2. 8 modules/webform_revisions/src/WebformRevisionsRequest.php \Drupal\webform_revisions\WebformRevisionsRequest::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 WebformRequest::isValidSourceEntity

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

File

modules/webform_revisions/src/WebformRevisionsRequest.php, line 323

Class

WebformRevisionsRequest
Handles webform requests.

Namespace

Drupal\webform_revisions

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;
  }
}