Problem/Motivation
The block title shows the incorrect menu item title.
Steps to reproduce
- Enable the latest dev release 8.x-1.x-dev.
- Create a basic page listed in the main navigation menu.
- Create another basic page with the above page's menu item as its parent.
- Place a Main Navigation block in sidebar first with
- initial visibility level set to 2, and
- block title as menu link parent enabled.
Expected Behavior
When you visit the both the parent and the child nodes, the title of the menu block should be the parent menu item.

This works as expected in 8.x-1.2.
Current Behavior
When you visit the child node, the title correctly shows the parent menu item title. However, when you visit the parent node, the title shows the block title rather than the parent menu item.

Proposed resolution
This bug seems to have been introduced by the recent fix to D9: Untrusted callback exception.
Adjustments to this logic may be necessary.
Comments
Comment #3
jcandan commentedComment #4
jcandan commentedIn order to fix the bug introduced, as per2925605 #21, this reverts the attempt made to show the direct parent of a menu item rather than the top-level parent. It still retains the fix applied to address D9: Untrusted callback exception.
Comment #5
jcandan commentedComment #6
tancAwesome, thanks very much for doing this. I’ll take a look tomorrow.
Comment #7
jcandan commentedSeems the Drupal 9 tests are failing due to some XML configuration error:
Local tests against Drupal 9 do pass; this error is internal to drupal.org, and is a false negative on this patch.
Looking forward to seeing this merged. Is a release up for consideration?
Comment #8
tancOf course!
The failing Drupal 9.2 tests need looking at, it isn't related to that XML config output as 3 of the tests pass and 2 fail. The failing tests are saying that the string can't be found in the html element. I can also replicate locally with Drupal 9.2 so there is something there to fix.
I'll look at that now.
Comment #9
tancOdd. When running the tests the menu block title does not change and always has
Main navas theH2so the tests fail. But using Stark theme and enabling the test module to manually replicate the test steps shows the menu block title changing as it should.Comment #10
tancTests pass in D9.1 so I've opened a specific issue for tests in 9.2: #3213343: Fix failing tests in D9.2.x
I'll focus now on the changes in this merge request but I think its looking really good.
Comment #11
jcandan commentedSince this is working for the latest release, Drupal 9.1.x, but due to the 9.2.x test bug may not be committed or release soon, I am providing the following patch for composer based patch workflows.
Comment #13
tancI've finally found some time to work on this.
Digging into this on the child issue #3213343: Fix failing tests in D9.2.x I worked out the router needs to be rebuilt so the tests see the updated menu block title. I could replicate the issue by installing a fresh D9.2.x with caching turned on (default) and the minimal install profile. Then installing the
menu_block_title_testmodule and clicking through to some child nodes. The sidebar menu H2 displayedMain navAfter executing
drush ev "\Drupal::service('router.builder')->rebuild();"the correct menu block title showed.I've merged the fix and re-run the tests on this merge request and all are now passing, so I've committed. The merge request got a bit messed up so I did the commit the old school way. I'll issue an updated module shortly.
Thanks again for your hard work on this!