Sometimes appears situation when we need to display the block title(as link) even when this menu item don't have child items.

My suggestion is add to the configuration form new checkbox, and check it if we need display empty block(only title).

Comments

sanchiz’s picture

StatusFileSize
new2.79 KB

Initial patch.

sanchiz’s picture

Status: Active » Needs review
davidhernandez’s picture

This patch worked for me as designed.

davidhernandez’s picture

I don't know if this is intentional or not, but it looks like when this is on, the menu block will still display, even on pages that are not in the menu.

dave reid’s picture

Status: Needs review » Needs work

I think it should only display if the current active trail is the same as the menu block selected menu.

euskarez’s picture

this patch is not applied on version 7.x-2.x-dev of the module.
i need of this feature.
someone can help me?

eric115’s picture

Status: Needs work » Needs review
StatusFileSize
new2.5 KB

Rerolled and updated patch to work with the changes to the way menu block works in the 7.x-2.x-dev version.

sam152’s picture

Status: Needs review » Needs work
  1. +++ b/menu_block.admin.inc
    @@ -327,6 +327,12 @@ function menu_block_configure_form($form, &$form_state) {
    +    '#title' => t('Display empty block'),
    +    '#description' => t('Display block if block content is empty'),
    

    Can we be consistent with the rest of the UI with full stops and case.

  2. +++ b/menu_block.module
    @@ -532,7 +533,15 @@ function menu_tree_build(array &$config) {
    +  elseif (isset($config['display_empty']) && $config['display_empty']) {
    

    !empty() is the only condition requried here.

  3. +++ b/menu_block.module
    @@ -532,7 +533,15 @@ function menu_tree_build(array &$config) {
    +  // isset check is to prevent menu blocks that haven't saved a patched admin form
    

    Maybe an empty div would be better here? It won't effect layouts in the same way a non breaking space will. Is there an even better way to render a block with no contents? I suspect not.

  4. +++ b/menu_block.module
    @@ -532,7 +533,15 @@ function menu_tree_build(array &$config) {
    +  // isset check is to prevent menu blocks that haven't saved a patched admin form
    

    Standards. No capital, breaks 80 columns.

eric115’s picture

StatusFileSize
new2.34 KB
new1.2 KB

Here is a new patch with Sam152's suggestions implemented.

eric115’s picture

Status: Needs work » Needs review

The last submitted patch, 1: menu_block-empty_block-2327795-1.patch, failed testing.

sam152’s picture

Status: Needs review » Reviewed & tested by the community

Looks pretty good for me. I'm guessing there wasn't an easy way to get the block to output with no markup whatsoever?

eric115’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new2.63 KB
new847 bytes

That is a good point, it looks like we can remove the "menu-block-wrapper" markup by not setting/nulling out the $data['content']['#theme'] variable.
This patch fixes that. Good catch!

sam152’s picture

Status: Needs review » Reviewed & tested by the community

Looking good.

johnalbin’s picture

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

Sometimes appears situation when we need to display the block title(as link) even when this menu item don't have child items.

Really? If the block title (as link) option is checked and there are no children, that means you are _on_ the page the block title would link to. [edit: oh! If the depth is limited, you might be on a page that is an descendant of the block title's page.]

Can someone update the issue description with a better explanation of why this is needed? I don't like to add new configuration for extreme edge cases; we have an API for that.

johnalbin’s picture

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

Good news! This is the default behavior in Drupal 8. [edit: whoops. I was wrong about this; there was a bug in the d8 version of menu_block.] It still doesn't make sense to me, but I trust it makes sense to some of you. [edit: I'll still trust you.] See #2757215: Add option to show block if menu tree contains no links

johnalbin’s picture

  • JohnAlbin committed 4f5168e on 7.x-2.x
    Issue #2327795 by Eric115, sanchiz, Sam152, JohnAlbin, davidhernandez:...
johnalbin’s picture

Status: Reviewed & tested by the community » Fixed

I stream-lined a little bit of the code, improved the UI, and committed it.

Status: Fixed » Closed (fixed)

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

tarik.cipix’s picture

This suddenly showed blocks that used to be hidden. Would be nice for a heads up in the release notes..