0

I want my menu block to decide whether to show link children based only on whether the menu link (or the entire menu block) is set to "Expanded", not whether you're currently on the same page as the link that has children. What's the best way to do this?

1 Answer 1

0

I'm currently doing this with hook_menu_block_alter() calling itself recursively:

function THEME_NAME_menu_block_tree_alter(&$tree, &$config) {
    if($config['expanded']) {
        return;
    }

    foreach($tree as $link_key => &$link) {
        if(!empty($link['below'])) {
            if(!$link['link']['expanded']) {
                $link['below'] = array();
            } else {
                THEME_NAME_menu_block_tree_alter($link['below'], $config);
            }
        }
    }

    unset($link);
}

But this feels super sketchy and I'm not at all confident that it's the best solution. I could break the foreach() into a separate recursive function, but that hardly seems different, other than my general icky feeling which I'm not sure there's even a logical reason for me to have.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.