[regression] Menu List Builder getEntityIds() no longer calls getEntityListQuery

Created on 20 December 2023, 6 months ago
Updated 12 June 2024, 13 days ago

Problem/Motivation

This change was introduced in 10.2 ✨ Sort menu list by menu title Fixed , which alphabetically sorts menus.

This was achieved by modifying getEntityIds() in MenuListBuilder

BEFORE
It inherited from EntityListBuilder

 protected function getEntityIds() {
    return $this->getEntityListQuery()->execute();
  }

AFTER


protected function getEntityIds() {
    $query = $this
      ->getStorage()
      ->getQuery()
      ->sort('label', 'ASC');

    // Only add the pager if a limit is specified.
    if ($this->limit) {
      $query->pager($this->limit);
    }
    return $query->execute();
  }

This delivers the sorted results, but achieves this by creating its own query instead of modifying $this->getEntityListQuery(). This caused problems on a project I was working on as it relies on customizing getEntityListQuery. I imagine we can still get the benefits introduced in #3070721 by modifying getEntityListQuery instead of introducing a new one.

Steps to reproduce

Proposed resolution

Call getEntityListQuery vs getEntityIds in core/modules/menu_ui/src/MenuListBuilder.php

Remaining tasks

Review
Commit

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

πŸ› Bug report
Status

RTBC

Version

11.0 πŸ”₯

Component
Menu UIΒ  β†’

Last updated 13 days ago

No maintainer
Created by

πŸ‡ΊπŸ‡ΈUnited States bnjmnm Ann Arbor, MI

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

Merge Requests

Comments & Activities

  • Issue created by @bnjmnm
  • πŸ‡ΊπŸ‡ΈUnited States bnjmnm Ann Arbor, MI
  • First commit to issue fork.
  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

    I see why this was done, now. You can't unset previously defined sorts.

    \Drupal\Core\Entity\EntityListBuilder::getEntityListQuery does:

    ->sort($this->entityType->getKey('id'));
    

    Any other sort calls would sort secondary to that one.

    Opening an MR that uses a query tag to alter the query and fix the sorts. It's not great but the only option.

  • Merge request !7890Use alter tag to modify sort β†’ (Open) created by mglaman
  • Status changed to Needs review about 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA
  • Pipeline finished with Failed
    about 2 months ago
    Total: 172s
    #162720
  • Pipeline finished with Canceled
    about 2 months ago
    Total: 48s
    #162768
  • Pipeline finished with Success
    about 2 months ago
    Total: 626s
    #162770
  • Status changed to Needs work about 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Something we could add test coverage for?

  • Status changed to Needs review 21 days ago
  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

    It feels more of a coding standard / PHPStan rule than test coverage. After reading 🌱 [policy, no patch] Better scoping for bug fix test coverage RTBC it seems like this could be a bugfix without a test, but should have a follow up for preventing this kinds of changes in entity list builders.

    Does the issue expose a general lack of test coverage for the specific subsystem? If so, is it better to add generic test coverage for that subsystem in a separate issue?

    Also, this is true:

    Is the fix achieved without adding new, untested, code paths?

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Mind updating proposed solution

    Fine with moving generic test coverage to a follow up.

  • Status changed to RTBC 15 days ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Went ahead and opened the follow up.

    Tweaked summary some.

    But change didn't break anything and does seem like the policy could apply.

  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

    Thanks for opening, added notes there. Sorry, it's been on my list but kept getting buried.

  • First commit to issue fork.
  • Merge request !8388Less code and more applicable fix β†’ (Open) created by alexpott
  • Status changed to Needs review 14 days ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Given this is not going to make 10.2.x can I suggest that we fix the original problem in a more generic and easier to override way - see https://git.drupalcode.org/project/drupal/-/merge_requests/8388

  • Pipeline finished with Success
    14 days ago
    Total: 541s
    #197093
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Oh nice so all you have to do is set a key. +1 from me but will let #mglaman mark it since he opened the issue.

  • Status changed to RTBC 13 days ago
  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

    Even better

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    alexpott β†’ changed the visibility of the branch 3410091-regression-menu-list to hidden.

Production build 0.69.0 2024