Problem/Motivation

#3379725: Make Block config entities fully validatable 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

Issue fork drupal-3520944

Command icon Show commands

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

wim leers created an issue. See original summary.

borisson_’s picture

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?

quietone’s picture

Version: 11.1.x-dev » 11.x-dev
phenaproxima’s picture

$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.

phenaproxima’s picture

EDIT: Never mind -- I was looking at the wrong thing.

borisson_’s picture

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

phenaproxima’s picture

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

longwave’s picture

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

phenaproxima’s picture

Issue tags: -Needs tests

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

phenaproxima’s picture

Status: Active » Needs review
Issue tags: -Needs update path tests

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

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

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.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

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

phenaproxima’s picture

Status: Needs work » Reviewed & tested by the community

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

bbrala’s picture

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.

longwave’s picture

Status: Reviewed & tested by the community » Needs work

Minor issue with the post-update hook.

phenaproxima’s picture

Status: Needs work » Reviewed & tested by the community

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

wim leers’s picture

#4: 🤣🤯 Truly ROFL when you wrote That constant is older than two of my nieces. 🤣

MenuLinkDepthConstraintValidator and its test coverage look excellent! 👏

  • longwave committed df9baa95 on 11.x
    Issue #3520944 by phenaproxima, wim leers, borisson_, longwave: Make...
longwave’s picture

Status: Reviewed & tested by the community » Fixed

Committed df9baa9 and pushed to 11.x. Thanks!

larowlan’s picture

Status: Fixed » Reviewed & tested by the community

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

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Gah, crosspost

larowlan’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.