Commit b82be539 authored by catch's avatar catch
Browse files

fix: #3532360 Check return value from getCurrentRequest() before calling...

fix: #3532360 Check return value from getCurrentRequest() before calling setRequest() in ViewExecutableFactory

By: aaronbauman
By: smustgrave
(cherry picked from commit b13c0284)
parent 8a115bd5
Loading
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -76,7 +76,10 @@ public function __construct(AccountInterface $user, RequestStack $request_stack,
   */
  public function get(ViewEntityInterface $view) {
    $view_executable = new ViewExecutable($view, $this->user, $this->viewsData, $this->routeProvider, $this->displayPluginManager);
    $view_executable->setRequest($this->requestStack->getCurrentRequest());
    $request = $this->requestStack->getCurrentRequest();
    if ($request) {
      $view_executable->setRequest($request);
    }
    return $view_executable;
  }

+13 −0
Original line number Diff line number Diff line
@@ -111,4 +111,17 @@ public function testGet(): void {
    $this->assertSame($executable->getUser(), $this->user);
  }

  /**
   * Tests the get method when current request is null.
   *
   * @legacy-covers ::get
   */
  public function testGetNoRequest(): void {
    $executable = $this->viewExecutableFactory->get($this->view);

    $this->assertInstanceOf('Drupal\views\ViewExecutable', $executable);
    $this->assertSame($executable->getUser(), $this->user);
    $this->assertSame($executable->getRequest(), NULL);
  }

}