Make menu blocks (block.settings.system_menu_block:*) fully validatable

Created on 24 April 2025, 21 days ago

Problem/Motivation

πŸ“Œ Make Block config entities fully validatable Fixed made Block config entities fully validatable, and the settings for 2 block plugins:

  1. content blocks (block.settings.block_content:*:) (see block_content.schema.yml
  2. the search form block block.settings.search_form_block (see search.schema.yml)

Steps to reproduce

N/A

Proposed resolution

Also make

block.settings.system_menu_block:*:
  type: block_settings
  label: 'Menu block'
  mapping:
    level:
      type: integer
      label: 'Starting level'
    depth:
      type: integer
      label: 'Maximum number of levels'
    expand_all_items:
      type: boolean
      label: 'Expand all items'

fully validatable.

Remaining tasks

  1. Validate level: must be between 0 and $this->menuTree->maxDepth()β†’ Range constraint?
  2. Validate depth: really relative depth, aka levels to display IF available. Currently 0 means "no limit". Must be between 1 and min($level + $depth - 1, $this->menuTree->maxDepth()).

    Wouldn't it be better to make depth optional, aka nullable: true? Then we don't need to assign a special meaning to 0

  3. Validate expand_all_items: either we accept that this is basically nonsense for a single-level menu, or we accept that it's really a "best effort" thing. I vote the latter, that seems pragmatic and simple.
  4. Update path + test coverage.

User interface changes

None.

Introduced terminology

None.

API changes

None.

Data model changes

TBD

Release notes snippet

TBD

πŸ“Œ Task
Status

Active

Version

11.1 πŸ”₯

Component

menu system

Created by

πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
  • Contributed project blocker

    It denotes an issue that prevents porting of a contributed project to the stable version of Drupal due to missing APIs, regressions, and so on.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @wim leers
  • πŸ‡§πŸ‡ͺBelgium borisson_ Mechelen, πŸ‡§πŸ‡ͺ

    Validate level: must be between 0 and $this->menuTree->maxDepth()β†’ Range constraint?

    Can a range constraint be variable like this, or should we fall back to the same thing with did for weight and say it is somewhere between 0 and PHP_INT_MAX?

  • πŸ‡³πŸ‡ΏNew Zealand quietone
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    $this->menuTree->maxDepth()

    Fun fact: \Drupal\Core\Menu\MenuLinkTree::maxDepth() calls \Drupal\Core\Menu\MenuTreeStorage::maxDepth(), which does no computation at all, but merely returns...a constant (\Drupal\Core\Menu\MenuTreeStorage::MAX_DEPTH).

    That constant is older than two of my nieces. It was created in #2301239: MenuLinkNG part1 (no UI or conversions): plugins (static + MenuLinkContent) + MenuLinkManager + MenuTreeStorage β†’ and appears to have been completely unchanged since.

    So, to get this issue done faster, I propose that we don't even need to worry about having a special constraint to determine the max depth dynamically. Let's just hard-code it, at least for now, based on the value of that constant, which has not been changed in core since it was introduced.

    That way, we'll get pretty strong validation done quickly, without a ton of effort, and we could make it a more flexible constraint later in a follow-up.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Wouldn't it be better to make depth optional, aka nullable: true? Then we don't need to assign a special meaning to 0

    Not sure we should do that, as it would constitute an API change for...what benefit, exactly? Maybe a separate issue would be better here.

  • πŸ‡§πŸ‡ͺBelgium borisson_ Mechelen, πŸ‡§πŸ‡ͺ

    The analysis in #4 looks great! That means we can do it easily with the same flexibility of constraint we have today. +1 to this approach

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Wrote the update path. But it does need an explicit validation test.

  • Pipeline finished with Failed
    21 days ago
    Total: 138s
    #481317
  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Don't we also need a constraint adding to depth?

  • Pipeline finished with Failed
    20 days ago
    Total: 266s
    #481522
  • Pipeline finished with Failed
    17 days ago
    Total: 197s
    #483830
  • Pipeline finished with Failed
    17 days ago
    Total: 148s
    #483838
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Tests written. Just need to test that ol' update path!

  • Pipeline finished with Failed
    17 days ago
    Total: 133s
    #483843
  • Pipeline finished with Canceled
    17 days ago
    Total: 141s
    #483861
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    And, added an update path test. I think this is reviewable now.

  • Pipeline finished with Failed
    17 days ago
    Total: 537s
    #483863
  • Pipeline finished with Failed
    16 days ago
    Total: 512s
    #483891
  • Pipeline finished with Failed
    16 days ago
    Total: 749s
    #483942
  • Pipeline finished with Failed
    16 days ago
    Total: 548s
    #483970
  • Pipeline finished with Running
    16 days ago
    #483990
  • Pipeline finished with Failed
    16 days ago
    Total: 1330s
    #483975
  • Pipeline finished with Success
    16 days ago
    Total: 423s
    #484006
  • πŸ‡§πŸ‡ͺBelgium borisson_ Mechelen, πŸ‡§πŸ‡ͺ

    Tests are green, that's great! I think the new constraint also makes a lot of sense.
    There's an upgrade path and the changes to tests also look good.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Just one minor comment about the deprecation notice linking to a CR instead of an issue nid
    Fine to self RTBC

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Wrote a CR and linked to it from the deprecation message, so back to RTBC per #13.

  • Pipeline finished with Success
    14 days ago
    #485997
  • πŸ‡³πŸ‡±Netherlands bbrala Netherlands

    Was going to ask why we are not calling this Depth instead of MaxLinkDepth and coupling to the menu. But seems getting maxDepth in some other way it rather hard. So guess my thoughts are a no-op.

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Minor issue with the post-update hook.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Moving the update path around was a very minor lift, so restoring RTBC here on the assumption that tests will pass.

  • Pipeline finished with Success
    13 days ago
    Total: 848s
    #486678
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    #4: 🀣🀯 Truly ROFL when you wrote 🀣

    MenuLinkDepthConstraintValidator and its test coverage look excellent! πŸ‘

    • longwave β†’ committed df9baa95 on 11.x
      Issue #3520944 by phenaproxima, wim leers, borisson_, longwave: Make...
  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Committed df9baa9 and pushed to 11.x. Thanks!

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    @longwave the MR was closed but it doesn't look like this was committed/pushed - was that by mistake?

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Gah, crosspost

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10
Production build 0.71.5 2024