Verified Commit 23bb407d authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2002012 by dimitriskr, dawehner, smustgrave, quietone, damiankloip,...

Issue #2002012 by dimitriskr, dawehner, smustgrave, quietone, damiankloip, catch: Inject the display plugin manager into the view and view factory
parent ee4eaba6
Loading
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\views\Plugin\views\display\DisplayRouterInterface;
use Drupal\views\Plugin\ViewsPluginManager;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
@@ -471,14 +472,21 @@ class ViewExecutable {
   *   The views data.
   * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
   *   The route provider.
   * @param \Drupal\views\Plugin\ViewsPluginManager|null $displayPluginManager
   *   The plugin manager for display.
   */
  public function __construct(ViewEntityInterface $storage, AccountInterface $user, ViewsData $views_data, RouteProviderInterface $route_provider) {
  public function __construct(ViewEntityInterface $storage, AccountInterface $user, ViewsData $views_data, RouteProviderInterface $route_provider, protected ?ViewsPluginManager $displayPluginManager = NULL) {
    // Reference the storage and the executable to each other.
    $this->storage = $storage;
    $this->storage->set('executable', $this);
    $this->user = $user;
    $this->viewsData = $views_data;
    $this->routeProvider = $route_provider;
    if ($this->displayPluginManager === NULL) {
      @trigger_error('Calling ' . __METHOD__ . ' without the $displayPluginManager argument is deprecated in drupal:10.3.0 and it will be required in drupal:12.0.0. See https://www.drupal.org/node/3410349', E_USER_DEPRECATED);
      $this->displayPluginManager = \Drupal::service('plugin.manager.views.display');
    }

  }

  /**
@@ -738,9 +746,8 @@ public function initDisplay() {
    if (isset($this->current_display)) {
      return TRUE;
    }

    // Initialize the display cache array.
    $this->displayHandlers = new DisplayPluginCollection($this, Views::pluginManager('display'));
    $this->displayHandlers = new DisplayPluginCollection($this, $this->displayPluginManager);

    $this->current_display = 'default';
    $this->display_handler = $this->displayHandlers->get('default');
@@ -2097,6 +2104,7 @@ public function destroy() {
      $defaults['user'],
      $defaults['request'],
      $defaults['routeProvider'],
      $defaults['displayPluginManager'],
      $defaults['viewsData']
    );

@@ -2535,6 +2543,7 @@ public function __wakeup() {
      $this->user = \Drupal::currentUser();
      $this->viewsData = \Drupal::service('views.views_data');
      $this->routeProvider = \Drupal::service('router.route_provider');
      $this->displayPluginManager = \Drupal::service('plugin.manager.views.display');

      // Restore the state of this executable.
      if ($request = \Drupal::request()) {
+9 −2
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\views\Plugin\ViewsPluginManager;
use Symfony\Component\HttpFoundation\RequestStack;

/**
@@ -50,12 +51,18 @@ class ViewExecutableFactory {
   *   The views data.
   * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
   *   The route provider.
   * @param \Drupal\views\Plugin\ViewsPluginManager|null $displayPluginManager
   *   The display plugin manager.
   */
  public function __construct(AccountInterface $user, RequestStack $request_stack, ViewsData $views_data, RouteProviderInterface $route_provider) {
  public function __construct(AccountInterface $user, RequestStack $request_stack, ViewsData $views_data, RouteProviderInterface $route_provider, protected ?ViewsPluginManager $displayPluginManager = NULL) {
    $this->user = $user;
    $this->requestStack = $request_stack;
    $this->viewsData = $views_data;
    $this->routeProvider = $route_provider;
    if ($this->displayPluginManager === NULL) {
      @trigger_error('Calling ' . __METHOD__ . ' without the $displayPluginManager argument is deprecated in drupal:10.3.0 and it will be required in drupal:12.0.0. See https://www.drupal.org/node/3410349', E_USER_DEPRECATED);
      $this->displayPluginManager = \Drupal::service('plugin.manager.views.display');
    }
  }

  /**
@@ -68,7 +75,7 @@ public function __construct(AccountInterface $user, RequestStack $request_stack,
   *   A ViewExecutable instance.
   */
  public function get(ViewEntityInterface $view) {
    $view_executable = new ViewExecutable($view, $this->user, $this->viewsData, $this->routeProvider);
    $view_executable = new ViewExecutable($view, $this->user, $this->viewsData, $this->routeProvider, $this->displayPluginManager);
    $view_executable->setRequest($this->requestStack->getCurrentRequest());
    return $view_executable;
  }
+1 −0
Original line number Diff line number Diff line
@@ -374,6 +374,7 @@ protected function assertViewDestroy(ViewExecutable $view): void {
      $defaults['user'],
      $defaults['request'],
      $defaults['routeProvider'],
      $defaults['displayPluginManager'],
      $defaults['viewsData']
    );

+3 −1
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
use Drupal\Tests\UnitTestCase;
use Drupal\views\Entity\View;
use Drupal\views\Plugin\views\pager\PagerPluginBase;
use Drupal\views\Plugin\ViewsPluginManager;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\area\Result;
use Drupal\views\ViewsData;
@@ -47,7 +48,8 @@ protected function setUp(): void {
    $user = $this->prophesize(AccountInterface::class)->reveal();
    $views_data = $this->prophesize(ViewsData::class)->reveal();
    $route_provider = $this->prophesize(RouteProviderInterface::class)->reveal();
    $this->view = new ViewExecutable($storage->reveal(), $user, $views_data, $route_provider);
    $display_plugin_manager = $this->prophesize(ViewsPluginManager::class)->reveal();
    $this->view = new ViewExecutable($storage->reveal(), $user, $views_data, $route_provider, $display_plugin_manager);

    $this->resultHandler = new Result([], 'result', []);
    $this->resultHandler->view = $this->view;
+4 −1
Original line number Diff line number Diff line
@@ -73,7 +73,10 @@ protected function setUp(): void {
      ->disableOriginalConstructor()
      ->getMock();
    $route_provider = $this->createMock('Drupal\Core\Routing\RouteProviderInterface');
    $this->view = new ViewExecutable($storage, $user, $views_data, $route_provider);
    $display_plugin_manager = $this->getMockBuilder('\Drupal\views\Plugin\ViewsPluginManager')
      ->disableOriginalConstructor()
      ->getMock();
    $this->view = new ViewExecutable($storage, $user, $views_data, $route_provider, $display_plugin_manager);

    $this->display = $this->getMockBuilder('Drupal\views\Plugin\views\display\DisplayPluginBase')
      ->disableOriginalConstructor()
Loading