Closed (fixed)
Project:
Drupal core
Version:
11.x-dev
Component:
menu system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
24 Apr 2025 at 10:45 UTC
Updated:
20 May 2025 at 03:09 UTC
Jump to comment: Most recent
#3379725: Make Block config entities fully validatable made Block config entities fully validatable, and the settings for 2 block plugins:
block.settings.block_content:*:) (see block_content.schema.ymlblock.settings.search_form_block (see search.schema.yml)N/A
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.
level: must be between 0 and $this->menuTree->maxDepth()→ Range constraint?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
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.None.
None.
None.
TBD
TBD
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
Comment #2
borisson_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?
Comment #3
quietone commentedComment #4
phenaproximaFun 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.
Comment #5
phenaproximaEDIT: Never mind -- I was looking at the wrong thing.
Comment #6
borisson_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
Comment #8
phenaproximaWrote the update path. But it does need an explicit validation test.
Comment #9
longwaveDon't we also need a constraint adding to
depth?Comment #10
phenaproximaTests written. Just need to test that ol' update path!
Comment #11
phenaproximaAnd, added an update path test. I think this is reviewable now.
Comment #12
borisson_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.
Comment #13
larowlanJust one minor comment about the deprecation notice linking to a CR instead of an issue nid
Fine to self RTBC
Comment #14
phenaproximaWrote a CR and linked to it from the deprecation message, so back to RTBC per #13.
Comment #15
bbralaWas 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.
Comment #16
longwaveMinor issue with the post-update hook.
Comment #17
phenaproximaMoving the update path around was a very minor lift, so restoring RTBC here on the assumption that tests will pass.
Comment #18
wim leers#4: 🤣🤯 Truly ROFL when you wrote 🤣
MenuLinkDepthConstraintValidatorand its test coverage look excellent! 👏Comment #20
longwaveCommitted df9baa9 and pushed to 11.x. Thanks!
Comment #22
larowlan@longwave the MR was closed but it doesn't look like this was committed/pushed - was that by mistake?
Comment #23
larowlanGah, crosspost
Comment #24
larowlan