ViewExecutableFactory.php 1.33 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Contains \Drupal\views\ViewExecutableFactory.
 */

namespace Drupal\views;

10
use Drupal\Core\Session\AccountInterface;
11
use Drupal\views\ViewStorageInterface;
12
use Symfony\Component\HttpFoundation\RequestStack;
13 14 15 16 17 18

/**
 * Defines the cache backend factory.
 */
class ViewExecutableFactory {

19 20 21 22 23 24 25
  /**
   * Stores the current user.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $user;

26 27 28 29 30 31 32
  /**
   * The request stack.
   *
   * @var \Symfony\Component\HttpFoundation\RequestStack
   */
  protected $requestStack;

33 34 35 36 37
  /**
   * Constructs a new ViewExecutableFactory
   *
   * @param \Drupal\Core\Session\AccountInterface $user
   *   The current user.
38 39
   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
   *   The request stack.
40
   */
41
  public function __construct(AccountInterface $user, RequestStack $request_stack) {
42
    $this->user = $user;
43
    $this->requestStack = $request_stack;
44 45
  }

46 47 48
  /**
   * Instantiates a ViewExecutable class.
   *
49
   * @param \Drupal\views\ViewStorageInterface $view
50 51 52 53 54
   *   A view entity instance.
   *
   * @return \Drupal\views\ViewExecutable
   *   A ViewExecutable instance.
   */
55
  public function get(ViewStorageInterface $view) {
56 57 58
    $view = new ViewExecutable($view, $this->user);
    $view->setRequest($this->requestStack->getCurrentRequest());
    return $view;
59 60 61
  }

}