You are here

public function ViewRevisionsRequest::getCurrentView in Config Entity Revisions 8

Same name and namespace in other branches
  1. 1.x modules/views_revisions/src/ViewsRevisionsRequest.php \Drupal\views_revisions\ViewRevisionsRequest::getCurrentView()
1 call to ViewRevisionsRequest::getCurrentView()
ViewRevisionsRequest::getViewEntities in modules/views_revisions/src/ViewsRevisionsRequest.php

File

modules/views_revisions/src/ViewsRevisionsRequest.php, line 162

Class

ViewRevisionsRequest
Handles view requests.

Namespace

Drupal\views_revisions

Code

public function getCurrentView() {
  $source_entity = static::getCurrentSourceEntity('view');
  if ($source_entity && ($view = $this->viewEntityReferenceManager
    ->getView($source_entity))) {
    return $view;
  }
  $view = $this->routeMatch
    ->getParameter('view');
  if (is_string($view)) {
    $controller = ViewRevisionsController::create(\Drupal::getContainer());
    $revisionId = $source_entity
      ->get('view_revision')
      ->getValue();
    if ($revisionId) {
      $revisionId = $revisionId[0]['target_id'];
    }
    else {

      // Get the id by getting the default view's third party settings.
      $view = $this->entityTypeManager
        ->getStorage('view')
        ->load($view);
      $content_entity_id = $view
        ->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();
    }
    $view = $controller
      ->loadConfigEntityRevision($revisionId);
  }
  return $view;
}