You are here

public function WebformRevisionsRequest::getCurrentWebform 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::getCurrentWebform()
  2. 8 modules/webform_revisions/src/WebformRevisionsRequest.php \Drupal\webform_revisions\WebformRevisionsRequest::getCurrentWebform()

Get webform associated with the current request.

Return value

\Drupal\webform\WebformInterface|null The current request's webform.

Overrides WebformRequest::getCurrentWebform

1 call to WebformRevisionsRequest::getCurrentWebform()
WebformRevisionsRequest::getWebformEntities in modules/webform_revisions/src/WebformRevisionsRequest.php
Get the webform and source entity for the current request.

File

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

Class

WebformRevisionsRequest
Handles webform requests.

Namespace

Drupal\webform_revisions

Code

public function getCurrentWebform() {
  $source_entity = static::getCurrentSourceEntity('webform');
  if ($source_entity && ($webform = $this->webformEntityReferenceManager
    ->getWebform($source_entity))) {
    return $webform;
  }
  $webform = $this->routeMatch
    ->getParameter('webform');
  if (is_string($webform)) {
    $controller = WebformRevisionsController::create(\Drupal::getContainer());
    $revisionId = $source_entity
      ->get('webform_revision')
      ->getValue();
    if ($revisionId) {
      $revisionId = $revisionId[0]['target_id'];
    }
    else {

      // Get the id by getting the default webform's third party settings.
      $webform = $this->entityTypeManager
        ->getStorage('webform')
        ->load($webform);
      $content_entity_id = $webform
        ->getContentEntityID();

      // Get the first revision id.
      $revisionId = \Drupal::database()
        ->query('SELECT MIN(revision) FROM {config_entity_revisions_revision} c WHERE c.id = :id', [
        ':id' => $content_entity_id,
      ])
        ->fetchField();
    }
    $webform = $controller
      ->loadConfigEntityRevision($revisionId);
  }
  return $webform;
}