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.

CommentFileSizeAuthor
#3 3579661.patch647 byteskevinvb

Issue fork drupal-3579661

Command icon 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:

Comments

kevinvb created an issue. See original summary.

kevinvb’s picture

StatusFileSize
new647 bytes

Added a patch for composer patching

kevinvb’s picture

Status: Active » Needs review
smustgrave’s picture

Version: 11.3.x-dev » main
Status: Needs review » Needs work

Thanks for reporting. Issues need to land in the main branch first. Would be good to get test coverage for this possibly too.

pameeela’s picture

Just spotted this issue while working on Drupal CMS, can confirm I'm seeing the same.

sivaji_ganesh_jojodae made their first commit to this issue’s fork.

sivaji_ganesh_jojodae changed the visibility of the branch 3579661-call-to-a to hidden.

sivaji_ganesh_jojodae’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

@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

penyaskito made their first commit to this issue’s fork.

penyaskito’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Faced 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 getContentEntityFromRoute which already did the check.
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Bug Smash Initiative, +Needs Review Queue Initiative

Saving 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

Error: Call to a member function getPath() on null
/var/www/html/core/modules/navigation/src/EntityRouteHelper.php:47
/var/www/html/core/modules/navigation/tests/src/Kernel/NavigationEntityRouteHelperTest.php:42

No objections to the change. LGTM.

catch’s picture

Version: main » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to main and cherry--picked to 11.x and 11.3.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • catch committed 32413a22 on 11.3.x
    fix: #3579661 Call to a member function getPath() on null in...

  • catch committed e2767d1c on 11.x
    fix: #3579661 Call to a member function getPath() on null in...

  • catch committed c6836648 on main
    fix: #3579661 Call to a member function getPath() on null in...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.