Problem/Motivation
When trying to access a non existing page with navigation module enabled an error is thrown:
Error: Call to a member function getPath() on null in Drupal\navigation\EntityRouteHelper->isContentEntityRoute() (line 54 of core/modules/navigation/src/EntityRouteHelper.php).
Full stack
Error: Call to a member function getPath() on null in Drupal\navigation\EntityRouteHelper->isContentEntityRoute() (line 54 of core/modules/navigation/src/EntityRouteHelper.php).
Drupal\navigation\EntityRouteHelper->isContentEntityRoute() (Line: 272)
Drupal\navigation\NavigationRenderer->getLocalTasks() (Line: 319)
Drupal\navigation\NavigationRenderer->hasLocalTasks() (Line: 77)
Drupal\navigation\Plugin\TopBarItem\PageActions->build() (Line: 39)
Drupal\navigation\TopBarItemManager->getRenderedTopBarItemsByRegion() (Line: 54)
Drupal\navigation\Element\TopBar::preRenderTopBar()
Steps to reproduce
Drupal 11.3.5
Navigation module enabled
Access a random path
Proposed resolution
Better check in EntityRouteHelper
In https://www.drupal.org/project/drupal/issues/3565886 the getContentEntityFromRoute was adapted but the isContentEntityRoute can still try to access getPath when getRouteObject returns NULL.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3579661.patch | 647 bytes | kevinvb |
Issue fork drupal-3579661
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:
- 3579661-getPath
changes, plain diff MR !15585
- 3579661-call-to-a
changes, plain diff MR !15109
Comments
Comment #3
kevinvb commentedAdded a patch for composer patching
Comment #4
kevinvb commentedComment #5
smustgrave commentedThanks for reporting. Issues need to land in the main branch first. Would be good to get test coverage for this possibly too.
Comment #6
pameeela commentedJust spotted this issue while working on Drupal CMS, can confirm I'm seeing the same.
Comment #10
sivaji_ganesh_jojodae commentedComment #11
smustgrave commented@sivaji did you just take the patch and make an ME or try a new solution?
There is a main MR already open that may just need a rebase
Either way probably should get test coverage
Thanks
Comment #13
penyaskitoFaced this too with Drupal CMS.
Renamed the test so we don't really need an extra kernel test when it's just a single call.
Changed the initial patch for the sake of consistency with
getContentEntityFromRoutewhich already did the check.Comment #14
smustgrave commentedSaving credit for @kevinvb for the original patch and @penyaskito for the test coverage.
Since I didn't want to start a new pipeline to run the test-only just did it locally
No objections to the change. LGTM.
Comment #15
catchCommitted/pushed to main and cherry--picked to 11.x and 11.3.x, thanks!