ViewExecutableFactory.php 1.84 KB
Newer Older
1 2 3 4
<?php

namespace Drupal\views;

5
use Drupal\Core\Routing\RouteProviderInterface;
6
use Drupal\Core\Session\AccountInterface;
7
use Symfony\Component\HttpFoundation\RequestStack;
8 9 10 11 12 13

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

14 15 16 17 18 19 20
  /**
   * Stores the current user.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $user;

21 22 23 24 25 26 27
  /**
   * The request stack.
   *
   * @var \Symfony\Component\HttpFoundation\RequestStack
   */
  protected $requestStack;

28 29 30 31 32 33 34
  /**
   * The views data.
   *
   * @var \Drupal\views\ViewsData
   */
  protected $viewsData;

35 36 37 38 39 40 41
  /**
   * The route provider.
   *
   * @var \Drupal\Core\Routing\RouteProviderInterface
   */
  protected $routeProvider;

42 43 44 45 46
  /**
   * Constructs a new ViewExecutableFactory
   *
   * @param \Drupal\Core\Session\AccountInterface $user
   *   The current user.
47 48
   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
   *   The request stack.
49 50
   * @param \Drupal\views\ViewsData $views_data
   *   The views data.
51 52
   * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
   *   The route provider.
53
   */
54
  public function __construct(AccountInterface $user, RequestStack $request_stack, ViewsData $views_data, RouteProviderInterface $route_provider) {
55
    $this->user = $user;
56
    $this->requestStack = $request_stack;
57
    $this->viewsData = $views_data;
58
    $this->routeProvider = $route_provider;
59 60
  }

61 62 63
  /**
   * Instantiates a ViewExecutable class.
   *
64
   * @param \Drupal\views\ViewEntityInterface $view
65 66 67 68 69
   *   A view entity instance.
   *
   * @return \Drupal\views\ViewExecutable
   *   A ViewExecutable instance.
   */
70
  public function get(ViewEntityInterface $view) {
71
    $view = new ViewExecutable($view, $this->user, $this->viewsData, $this->routeProvider);
72 73
    $view->setRequest($this->requestStack->getCurrentRequest());
    return $view;
74 75 76
  }

}