I'm attempting to use hook_block_view_alter()
to set a block title to the name of the page's parent menu item.
The block is a menu block for the main menu that is showing second-level items.
I've found that this works to set the title:
/**
* Implements hook_block_view_alter().
*/
function nama_components_block_view_alter(array &$build, \Drupal\Core\Block\BlockPluginInterface $block) {
if ($build['#id'] == 'nama_d8_main_menu') {
$parent_menu_item = 'just testing!';
$build['#configuration']['label'] = $parent_menu_item;
$build['#configuration']['label_display'] = 1;
}
}
From here, how would I look up the parent menu item from the block so I can actually set $parent_menu_item
? I've looked through what I'm getting in the $build
and $block
parameters, but I'm just not seeing it.