Problem/Motivation

#2756675: Add option to make the starting level follow the active menu item introduced new configuration options, but these options are not defined in menu_block.schema.yml

Proposed resolution

Implement config schema for block.settings.menu_block.*.{follow, follow_parent}

Remaining tasks

  1. Write a patch
  2. Review
  3. Commit

User interface changes

None.

API changes

None.

Data model changes

The data type for block.settings.menu_block.*.{follow, follow_parent} may change to the data type defined in menu_block.schema.yml

Release notes snippet

Implemented config schema for block.settings.menu_block.*.{follow, follow_parent}

Comments

idebr created an issue. See original summary.

idebr’s picture

Status: Active » Needs review
StatusFileSize
new1.63 KB

Attached patch implements configuration schema data for block.settings.menu_block.*.{follow, follow_parent} as well as an hook_update_N() to fix existing block configuration.

Joshua_Lim’s picture

i cannot apply this patch??

it says

error: config/schema/menu_block.schema.yml: no such file or directory

why?? i put the patchfile inthe schema folder and also tried to put it in the menu_block folder and apply the patch. it will not work

sorry i'm a beginner

it also says if its in the directory outside
error: menu_block.install: no such file or directory

jeroent’s picture

Status: Needs review » Reviewed & tested by the community

Tried the patch and worked as expected.

jeroent’s picture

I created #3038396: Add automated tests to add tests to the menu_block module, to prevent issues like this in the future.

jeroent’s picture

This issue is also blocking the tests for menu_multilingual: #3037173: Create tests

joelpittet’s picture

Status: Reviewed & tested by the community » Needs review

Thank you both @idebr and @JeroenT for moving this patch along.

+++ b/menu_block.install
@@ -12,3 +12,14 @@ function menu_block_update_8101() {
+function menu_block_update_8102() {
...
+  foreach ($config_factory->listAll('block.block.') as $block_config_name) {
+    $block = $config_factory->getEditable($block_config_name);

Do we need to do this against all blocks or is there a way we could do this against just the menu blocks? There may not be but I'd like to check.

jeroent’s picture

Added check to only update existing menu_blocks.

idebr’s picture

Status: Needs review » Needs work

We can take inspiration from an issue in Drupal core that added a key 'expand_all_items' to system_menu_block configuration #2594425: Add the option in system menu block to "Expand all items in this tree"

  1. Move the update from hook_update_N() to a post_update function, so the full Drupal API becomes available
  2. Use the ConfigEntityUpdater to make updating easier.

The relevant code in the related issue:


/**
 * Initialize 'expand_all_items' values to system_menu_block.
 */
function system_post_update_add_expand_all_items_key_in_system_menu_block(&$sandbox = NULL) {
  if (!\Drupal::moduleHandler()->moduleExists('block')) {
    return;
  }
  \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'block', function ($block) {
    return strpos($block->getPluginId(), 'system_menu_block:') === 0;
  });
}
jeroent’s picture

Status: Needs work » Needs review
StatusFileSize
new1.51 KB

Good suggestion.

Tried making a post_update hook. For some reason $block->get('settings.follow') and $block->set('settings.follow') did not work, so I tried a workaround.

idebr’s picture

Status: Needs review » Needs work

The post_update hook works great! Two minor points before this is ready:

  1. Menu block does not list Block as a dependency, so we'll have to check if the block module is enabled similar to the example code in #9. Otherwise the update will crash your site:
    The following updates are pending:
    
    menu_block module :
      Implement config schema for the menu_block settings follow.
    
    Do you wish to run all pending updates? (y/n): y
    Post updating menu_block                                                                                                                                                  [ok]
    Failed: Drupal\Component\Plugin\Exception\PluginNotFoundException: The "block" entity type does not exist. in                                                   [error]
    Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 150 of /[...]/core/lib/Drupal/Core/Entity/EntityTypeManager.php).
    Cache rebuild complete.                                                                                                                                                   [ok]
    Finished performing updates.
    
  2. +++ b/menu_block.post_update.php
    @@ -0,0 +1,26 @@
    +      return FALSE;
    +    })
    +  ;
    

    Code style: the ; should be on the previous line.

jeroent’s picture

Status: Needs work » Needs review
StatusFileSize
new649 bytes
new1.58 KB

1. Fixed. Added a check if the block module is enabled.
2. Fixed.

jeroent’s picture

Fixed a small nitpick.

idebr’s picture

Status: Needs review » Reviewed & tested by the community

The post_update implementation now works correctly when the Block module is not installed. It also updates the block configuration succesfully to the new configuration schema.

The indentation in #12 is correct according to the Drupal Code sniffer.

jeroent’s picture

jeroent’s picture

alison’s picture

  • joelpittet committed 6a2e5a8 on 8.x-1.x authored by JeroenT
    Issue #3022011 by JeroenT, idebr: Implement config schema for block....
joelpittet’s picture

Status: Reviewed & tested by the community » Fixed

Thank you all, I've pushed this to the dev release

Status: Fixed » Closed (fixed)

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

chris matthews’s picture