Since Drupal 8.7, Drupal core has been providing a "expand all menu items" checkbox on its menu block: #2594425: Add the option in system menu block to "Expand all items in this tree".

This is essentially a duplicate of the "Expand all menu links" option that this module provides.

The problem is that since this module's menu block extends from core's, both checkboxes appear, which is very confusing. Not only that, but it's impossible to actually enable the checkbox from core, because this module's block doesn't execute core's submit handler, so the config is never saved for that checkbox.

If a goal of this module is to have core eventually adopt its functionality, this is good. This means core as already started doing this. Now the challenge is we need to remove the config option from this module and use core's. This is not so easy because the configs are named differently. Core uses config key "expand_all_items" and this module just uses "expand". So there would need to be a migration path to update config for all usages of this plugin to use the key provided by core. Yikes. Not really practical since block configs can be anywhere these days.

Instead, we should at the very least hide this checkbox from core since it doesn't do anything.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bkosborne created an issue. See original summary.

bkosborne’s picture

Status: Active » Needs review
FileSize
685 bytes
1.49 KB

Let's try this...

bkosborne’s picture

Title: Remove "Expand all menu links" option, the core block recently started providing it » Remove duplicate "expand all menu items" checkbox introduced by core in Drupal 8.7

The last submitted patch, 2: 3133567-test-only.patch, failed testing. View results

dww’s picture

Thanks for opening this! It was reported (out of scope) at #2809699-100: Add configuration options for dynamic block titles. Nice to have a real place for addressing it. :)

Big +1 to removing the duplicate setting.

However, I think I'm -1 to the implementation here. Seems better (even if more complicated) to use core's setting for this, instead of hiding it. Yes, that means we need config migration, but that seems more future-proof than trying to hide core's and keep implementing our own. But I'm on the fence. Pragmatism says a 1.5kb patch (with test coverage!) that fixes a UI bug is a really good thing. Kinda hard to argue with that. ;) Thankfully, I'm not the maintainer, so it's not up to me to decide.

Meanwhile, the fact that we don't call core's submit handler seems problematic. I wonder if there are other settings that are being silently ignored. If so, that'd be another reason to fix this by removing our custom version and actually using core's SystemMenuBlock settings and functionality...

Cheers,
-Derek

Anybody’s picture

Yep, I agree with #5 - if it's the exactly SAME setting (same expected result), we should definitely use the core setting and merge them. If one of them is enabled, core should be enabled and the custom setting should be removed.

bkosborne’s picture

I agree it's better to use core's setting. But the update hook will be VERY complicated. If people could only use block plugins via the block UI (placing blocks into regions of a theme), it would be very easy. But people can use block plugins in Layout Builder, where the configuration for the blocks is serialized in the database in some cases, and in other cases is attached to entity view display config entities. There are probably other areas that people are using block configs as well via some other modules that let you embed blocks as paragraphs or in CKEditor or something.

One way to get around this problem is to NOT perform a config update since it's so impractical. Instead:

1) Remove this module's config for "expand" and fix submit handler so it saves the value of core's "expand_all_items" (currently being ignored)
2) When checking for the value of expand, first check if this module's "expand" config is set and use that. Otherwise use the value of core's "expand_all_items"

The downside here of course is that we're basically carrying around technical debt.

joelpittet’s picture

Category: Task » Bug report

@bkosborne why is the config update so impractical? I'm leaning towards fixing expand_all_items and updating config that used it to use core's.

I'm assuming you'd find all MenuBlock's check the status of expand and set the value of expand_all_items to that.

joelpittet’s picture

dww’s picture

@joelpittet re: #8:

Why is the config update so impractical?

Because of exactly what @bkosborne said in #7:

If people could only use block plugins via the block UI (placing blocks into regions of a theme), it would be very easy. But people can use block plugins in Layout Builder, where the configuration for the blocks is serialized in the database in some cases, and in other cases is attached to entity view display config entities. There are probably other areas that people are using block configs as well via some other modules that let you embed blocks as paragraphs or in CKEditor or something.

I like the compromise in #7 about having menu_block remain aware of both settings. Perhaps when saving, it can remove the legacy menu_block setting from config? That'd help folks migrate to the new setting over time. Perhaps we could do both, and have a post_update hook for the standard block config, but leave the fallback stuff for all the other block config edge cases? Yes, it means we've got some technical debt to clean up eventually, but it seems better than the technical debt of a really big complicated update that may or may not handle all the edge cases, anyway.

joelpittet’s picture

You both have more experience trying to solve the problem than I, I was hoping to do something similar to the update hook in interdiff for #2950943-37: Add links to menu parent block title but have never had to deal with those other config storage locations mentioned. Sorry I must have skipped over that explanation earlier @bkosborne

bkosborne’s picture

I'll also try to explain it a bit clearer too. There's really three concepts of blocks in core which is confusing:

  • block plugins - the code that actually renders output of a block. block plugins have settings forms, configuration, and output. The configuration must be stored somewhere.
  • block content - a content entity provided by optional core module "block content" to allow creating fieldable blocks. Each block content entity gets a block plugin defined for it dynamically.
  • block config entities - allows placing block plugins into regions in your site's theme. The configuration for the block plugin that is placed is stored inside this config entity.

That's just what core provides. There are other modules, like layout builder, that allow placing block plugins into a layout, and the config for the block plugins can be stored in two different areas for that.

Any contrib module that provides block plugins has this problem of not really being able to provide update paths for configuration of their plugins, because there are an unknown number of areas where the config is stored.

So the update hook example you provided in #11 works great but only for block config entities - AKA blocks placed into a themes regions.

cainaru’s picture

Here is a first pass at deprecating the "Expand all menu links" checkbox in favor of core's "Expand all menu items" checkbox. It includes a post_update hook for updating standard block config.

Status: Needs review » Needs work
godotislate’s picture

Status: Needs work » Needs review
FileSize
7.58 KB
2.55 KB

Updated patch to pass tests. Not sure whether additional tests are required.

godotislate’s picture

Small fix for backwards-compatibility with the expand property for blocks in Layout Builder, etc. Also small fixes for variable typing.

Kris77’s picture

seems to work for me with last dev version.

Thanks @godotislate

JurgenR’s picture

Status: Needs review » Reviewed & tested by the community

Patch #16 is working, thnx.

jeremyr’s picture

+1 for patch #16

joelpittet’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

I'm considering committing a solution but I'd like to know how the patch in #16 addresses #10 and #12 points about layout builder and core config updates?

godotislate’s picture

There's a post-update hook that updates all global menu block configurations, so that will happen when database updates are run.

There's nothing to update menu blocks in layout builder, and this is mainly due to complexity. It's probably feasible to go through all entity display view defaults layout and find menu blocks within to update them, though to do so is somewhat complex. However, for per-entity overrides, having to go through all content entities to find menu blocks placed in the layout builder field storage and update them might not be ideal, depending on the number of relevant entities.

Backwards-compatibility is provided for the saved settings, but the settings themselves won't get updated unless the blocks are re-saved.

Chris Matthews’s picture

Status: Postponed (maintainer needs more info) » Reviewed & tested by the community

Changing status back to RTBC per @godotislate's comments in #21.

joelpittet’s picture

Status: Reviewed & tested by the community » Fixed

Thanks everybody for your help on this, I've committed it to the dev release for the next release.

On commit, I changed the array_key_exists() to isset() checks because they are faster and besides NULL values are identical.

I have it a manual test to see what hiccups may arise as well.

Status: Fixed » Closed (fixed)

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