Problem/Motivation

The block title shows the incorrect menu item title.

Steps to reproduce

  1. Enable the latest dev release 8.x-1.x-dev.
  2. Create a basic page listed in the main navigation menu.
  3. Create another basic page with the above page's menu item as its parent.
  4. 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.

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

jcandan created an issue. See original summary.

jcandan’s picture

jcandan’s picture

In 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.

jcandan’s picture

tanc’s picture

Awesome, thanks very much for doing this. I’ll take a look tomorrow.

jcandan’s picture

Seems the Drupal 9 tests are failing due to some XML configuration error:

PHPUnit Test failed to complete; Error: PHPUnit 9.5.4 by Sebastian Bergmann and contributors.

Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

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?

tanc’s picture

Is a release up for consideration

Of 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.

tanc’s picture

Odd. When running the tests the menu block title does not change and always has Main nav as the H2 so 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.

tanc’s picture

Tests 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.

jcandan’s picture

Since 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.

  • tanc committed 1ea4aea on 8.x-1.x authored by jcandan
    Issue #3213200 by jcandan, tanc: Block title displayed rather than menu...
tanc’s picture

Status: Active » Fixed

I've finally found some time to work on this.

When running the tests the menu block title does not change and always has Main nav as the H2 so 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.

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_test module and clicking through to some child nodes. The sidebar menu H2 displayed Main nav

After 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!

Status: Fixed » Closed (fixed)

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