Problem/Motivation
An error is being thrown when navigating to URL that does not exist.
Error: Call to a member function getPath() on null in Drupal\navigation\EntityRouteHelper->getContentEntityFromRoute() (line 58 of /var/www/html/web/core/modules/navigation/src/EntityRouteHelper.php)
Steps to reproduce
Install Drupal, log in as administrator and navigate to a URL that does not exit in the system.
Proposed resolution
Change getContentEntityFromRoute method of EntityRouteHelper class to use Null-safe operator and cast the result to string to avoid using NULL as a key of the array and triggering a deprecation notice.
public function getContentEntityFromRoute(): ?ContentEntityInterface {
$route = $this->routeMatch->getRouteObject();
if (!$route) {
return NULL;
}
$path = $route->getPath();
if (!$entity_type = $this->getContentEntityPaths()[$path] ?? NULL) {
return NULL;
}
$entity = $this->routeMatch->getParameter($entity_type);
if ($entity instanceof ContentEntityInterface && $entity->getEntityTypeId() === $entity_type) {
return $entity;
}
return NULL;
}
Remaining tasks
None
User interface changes
None
Introduced terminology
None
API changes
None
Data model changes
None
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | Screenshot from 2026-01-12 13-06-27.png | 291.19 KB | sourav_paul |
| #19 | Screenshot from 2026-01-12 13-04-05.png | 126.61 KB | sourav_paul |
| #19 | Screenshot from 2026-01-12 12-42-10.png | 354.03 KB | sourav_paul |
| #7 | navigation issue (1).mp4 | 4.93 MB | diegodz |
| #5 | Screenshot from 2026-01-08 16-54-37.png | 96.35 KB | sourav_paul |
Issue fork drupal-3565886
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3565886-navigation-module-throws
changes, plain diff MR !14259
Comments
Comment #4
libbna commentedI was able to reproduce the issue on PHP v8.3 and resolved it as per the suggestion.
Comment #5
sourav_paulI've also get the same error on D11.3 with php 8.3, I've applied MR as a patch which has applied nice & cleanly. It resolved the issue.
Moving it to RTBC.
ss:

Comment #6
catchI think we should probably be getting the route object, checking whether it's null, and only then getting the path and seeing if it's in the content entity paths, otherwise we're checking if there's an empty string in the array with the current approach.
Also this could probably have test coverage.
Comment #7
diegodz commentedComment #8
diegodz commentedI am seeing a similar fatal error in Drupal 11 when accessing 404 pages with the
Navigation module enabled. Possibly the same root cause.
Comment #9
pjotr.savitski commented@catch I agree with the suggestion on the code side and that would be a lot more explicit and readable.
I suppose that the cleanest way to test that would be either to write a unit test that mocks all the constructor arguments or write a kernel test that fetched the service and test just that method with current request stack being given a request to non-existing path.
I wont get to writing the test code right now, but here is more or less the code you've described.
Comment #10
pjotr.savitski commented@diegodz Yes, that should be the same thing. The page content is served with code 404 and the error message is added to the end of the page. I did not initially notice the visuals and found that from the log.
Comment #11
pjotr.savitski commentedComment #12
diegodz commentedI've closed the other issue as a duplicate to keep everything centralized here.
As @pjotr.savitski also pointed out, the root cause isn't related to the entity. The error occurs when processing a request for a non-existent route (404), where the navigation module assumes a valid route/path object and calls getPath() if the result is null.
Comment #15
pjotr.savitski commentedComment #16
diegodz commentedI have applied this adjustment in the projects where the error was occurring, and in all cases it was successfully resolved.
Additionally, I performed manual QA to validate the correct behavior, and no further issues were identified.
Comment #17
f0ns commentedJust ran into this funky error and found this issue.
The suggested fix seems to solve the issue.
Comment #18
nicxvan commentedI ran the test only job, took me a second to find the new location!
I confirmed it fails with the expected error:
The video from diegodz confirms the fix applied as well.
I reviewed the code and the test, and I think there are two modules in the test that I'm not sure we need.
Not going to bump this out of RTBC at the moment, but it would be good to confirm.
Comment #19
sourav_paulI've tested the latest changes on D11.3 with php 8.3, Patch was applied cleanly & issue got resolved.
Sharing ss for reference.
Before:

After:

Applied patch:

RTBC +1
Thanks...
Comment #20
pjotr.savitski commentedComment #21
catchComment #22
casey commentedSnapshot of latest state of MR for safe usage with composer patches
Comment #23
berdirI think #3560106: Accessing a page that doesn't exist causes a fatal error in EntityRouteHelper::getContentEntityFromRoute() is another duplicate of this, need to check.
Comment #24
diegodz commentedHi @berdir, yes, it is indeed a duplicate. In fact, I also closed the thread https://www.drupal.org/project/drupal/issues/3566389 that I created when I realized it was related and wanted to centralize everything here.
You can see the video in comment #7 where you can see that it's the same problem.
Comment #30
larowlanCommitted to main and backported to 11.x and 11.3.x as the risk of disruption is low and this is a bug fix.