Missing css classes to menu items

Created on 8 November 2023, about 1 year ago
Updated 7 August 2024, 4 months ago

Problem/Motivation

The problem that I faced was that after migrating from version 1.x to 2.x there were some missing css classes on which my theme was relying for styling the menu items.

In version 1.x inside the buildForSitemap function (https://git.drupalcode.org/project/sitemap/-/blob/8.x-1.5/src/Menu/MenuL...) there was a $class variable which sets several classes, which are not present in the 2.x version.

Proposed resolution

I have created a patch, which adds the missing classes, but without the "first" and "last" classes, which are not needed for me.

Feature request
Status

Needs work

Component

Code

Created by

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

  • Issue created by @divanova
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    22 pass
  • Status changed to Needs work 4 months ago
  • 🇨🇦Canada mparker17 UTC-4

    @divanova, thank you very much for the contributon; and thank you for your patience with me!

    This patch looks great: the only thing that's preventing me from merging it is automated tests. I need automated tests, because I don't want future changes to the sitemap module to break this functionality, and break your website as a result!

    I think you could do this by modifying \Drupal\Tests\sitemap\Functional\SitemapMenuTest::testMenus() to include some more assertions. For example, the following checks for an "expanded" class on an HTML <a> tag with the link text $node_1_title...

    $this->assertEquals('expanded', $this->getSession()->getPage()->find('named', ['link', $node_1_title])->getAttribute('class'));
    

    ... note that example might not work (because I haven't checked it with the patch applied)... you'll have to look closer at the code in \Drupal\Tests\sitemap\Functional\SitemapMenuTest to see what it's supposed to do. You may also have to look at the the PHPUnit output files ("artifacts") to see what actually happens in the test environment.

    Thank you again!

Production build 0.71.5 2024