Problem/Motivation
Drupal\navigation\Hook\NavigationHooks::modulesInstalled() uses the following code.
// Do not modify config during sync. Config should be already consolidated.
if ($is_syncing) {
return;
}
foreach ($modules as $module) {
$blocks = $this->moduleHandler->invoke($module, 'navigation_defaults');
if (!is_array($blocks)) {
return;
}
foreach ($blocks as $block) {
$this->configActionManager->applyAction('addNavigationBlock', 'navigation.block_layout', $block);
}
}
It stops invoking those hook implementations after one of them returns a value that is different from the expected one.
navigation_install() uses instead the following code.
// Do not modify config during sync. Config should be already consolidated.
if ($is_syncing) {
return;
}
$blocks = \Drupal::moduleHandler()->invokeAll('navigation_defaults');
$manager = \Drupal::service('plugin.manager.config_action');
foreach ($blocks as $block) {
$manager->applyAction('addNavigationBlock', 'navigation.block_layout', $block);
}
Proposed resolution
Change Drupal\navigation\Hook\NavigationHooks::modulesInstalled() to use the following code.
// Do not modify config during sync. Config should be already consolidated.
if ($is_syncing) {
return;
}
foreach ($modules as $module) {
$blocks = $this->moduleHandler->invoke($module, 'navigation_defaults');
if (!is_array($blocks)) {
continue;
}
foreach ($blocks as $block) {
$this->configActionManager->applyAction('addNavigationBlock', 'navigation.block_layout', $block);
}
}
navigation_install() does not need to be changed, since ModuleHandler::invokeAll() returns an array.
Comments
Comment #2
avpadernoComment #4
avpadernoComment #5
avpadernoComment #6
smustgrave commentedCan we. get test coverage showing this please.
Comment #7
avpadernoComment #9
charlliequadros commentedHi, everyone!
Added the unit test `NavigationHooksTest::testModulesInstalledContinuesWhenModuleHasNoNavigationDefaults()` to cover the fix in `NavigationHooks::modulesInstalled()`.
The test uses two modules: one whose `hook_navigation_defaults()` implementation returns `NULL`, and another that returns a valid navigation block. It verifies that `ModuleHandlerInterface::invoke()` is called for both modules and that `ConfigActionManager::applyAction()` is called only once, for the valid block.
Comment #10
charlliequadros commented