Setting Use as title to "Active trail's root title" should respect Initial visibility level

Created on 16 November 2022, almost 2 years ago
Updated 7 June 2023, over 1 year ago

Problem/Motivation

Currently there is no way to set the block's title to the parent of the initial visibility level when this is set higher than level 2.
This is to me the expected behaviour when using "Active trail's root title", since the parent of the configured visibility level is the Active trail's root, however when is actually used is the 1st level item of the Active trail

Steps to reproduce

  1. Create a menu with the structure:
    • Food
      • Vegetables
      • Grains
        • Wheat
        • Barley
    • Drink
    • Equipment
  2. Add a menu block that will appear on the and pages with configured as 3 and configured as "Active trail's root title"
  3. Navigate to the or page
  4. Observe that the menu block contains and , but that the title is rather than

I don't imagine this is super useful to most people.

Proposed resolution

Update "Active trail's root title" to use the immediate parent of the visibility level rather than the 1st level item of the current trail. Have a patch ready for this.

An alternative approach would be to add a new option such as "Visible trail root" to avoid the situation where someone is intentionally using the current behaviour with a gap the trail (IMO this is unlikely, but people do their own thing).

Remaining tasks

Updated code has not yet been tested with "Make the initial visibility level follow the active menu item" option checked.

User interface changes

Menu Blocks with "Active trail's root title" set will display the parent of the visible portion of the active menu trail as the block title instead of the 1st level item in the trail as is used now.

API changes

None

Data model changes

In-memory only: Add a protected $menuRoot property to the Drupal\menu_block\Plugin\Block to propagate the $menu_root id from the build() method to the getActiveTrailRootTitle() method.

Feature request
Status

RTBC

Version

1.0

Component

Code

Created by

🇦🇺Australia Agileware

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India nikhil_110

    I implemented MR on my local machine using Menu Block Module V8.x-1.x-dev with Drupal 10.0.3. It is working properly..I have added the test steps and am attaching the screenshot for reference. Please review.

    • Setup Drupal with Menu Block v8.x-1.x-dev
    • Enabled Menu Block and Go to Administration > Administration > Structure > Menus > Create menu.
    • Go to Administration > Administration > Structure > Block layout > Click the "Place block" button in the desired regionand Choose a block from the "Menus" category. In the form that appears, configure the Advanced options and Use as title configured as "Active trail's root title" and Initial visibility level configured as 3
    • Go to Wheat and Barley page title is showing Grains.
  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Unable to generate test groups
  • 🇪🇨Ecuador jwilson3

    RTBC++ I applied MR diff to version 1.10 and can confirm that this change does indeed fix the issue.

    For purposes of calculating the Root title, the root should always be derived from the "initial visibility level" of the menu block, instead of using level 1, which may be too far up the tree to be practical.

    The only thing I noticed is a minor grammar issue with the docblock in the MR, which I have updated but will leave as RTBC because it is a non-functional change.

  • 🇨🇦Canada joelpittet Vancouver
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.1 + Environment: PHP 7.4 & MySQL 5.7
    last update 5 months ago
    Composer require failure
  • 🇺🇸United States zipymonkey Durham, NH

    The branch is out of date. I did a quick rebase locally and generated a patch (sorry for not updating the branch). I removed $this->tree = $tree; since it did not appear to be used anywhere.

  • Status changed to Needs review 5 months ago
  • 🇺🇸United States zipymonkey Durham, NH

    This patch is working for me locally. Moving this back to Needs Review for others to review.

  • 🇳🇿New Zealand chroid

    Assuming:

    Home > Conditions & Treatments > Childhood Cancer Overview > Tests & Procedures To Diagnose Cancer > Blood Tests For Children & Young People With Cancer

    Before patch:

    After patch:

    Menu block settings:

    Initial visibility level:
    3

    Use as title:
    Active trail's root title

    So confirming here that this is exactly what we were after!

    Thank you for the patch!

Production build 0.71.5 2024