Commit 32413a22 authored by catch's avatar catch
Browse files

fix: #3579661 Call to a member function getPath() on null in...

fix: #3579661 Call to a member function getPath() on null in EntityRouteHelper->isContentEntityRoute()

By: kevinvb
By: smustgrave
By: sivaji_ganesh_jojodae
By: penyaskito
(cherry picked from commit c6836648)
(cherry picked from commit e2767d1c)
parent 1a1999dd
Loading
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -51,7 +51,11 @@ public function __construct(
   *   TRUE if the content entity route condition is met, FALSE otherwise.
   */
  public function isContentEntityRoute(): bool {
    return array_key_exists($this->routeMatch->getRouteObject()->getPath(), $this->getContentEntityPaths());
    $route = $this->routeMatch->getRouteObject();
    if (!$route) {
      return FALSE;
    }
    return array_key_exists($route->getPath(), $this->getContentEntityPaths());
  }

  public function getContentEntityFromRoute(): ?ContentEntityInterface {
+6 −2
Original line number Diff line number Diff line
@@ -29,13 +29,17 @@ class NavigationEntityRouteHelperTest extends KernelTestBase {
  ];

  /**
   * Tests getContentEntityFromRoute() method when the route does not exist.
   * Tests entity route helper when the route does not exist.
   *
   * @see \Drupal\navigation\EntityRouteHelper::getContentEntityFromRoute
   * @see \Drupal\navigation\EntityRouteHelper::isContentEntityFromRoute
   */
  public function testGetContentEntityFromRouteWithNonExistentRoute(): void {
  public function testContentEntityFromRouteWithNonExistentRoute(): void {
    $request = Request::create('/does-not-exist');
    $response = $this->container->get('http_kernel')->handle($request);
    $this->assertEquals(404, $response->getStatusCode());
    $this->assertNull($this->container->get('navigation.entity_route_helper')->getContentEntityFromRoute());
    $this->assertFalse($this->container->get('navigation.entity_route_helper')->isContentEntityRoute());
  }

}