Hi, I'm testing taxonomy_context (trying to quit from taxonomy_menu module), so far I'm quite happy but trying to configure some details.

I wanted to know if there is a way to display menus on context block, expanded by default.

Best regards,
Mguel

CommentFileSizeAuthor
#5 taxonomy_context.module.patch1.97 KBlee20

Comments

Mguel’s picture

OK, although I don't know php, I manages to modify the taxonomy_context module to make the menu appear expanded by default on the block:

Code starting at line 450

      $children .= taxonomy_context_menu_tree($vid, $term->tid, FALSE);
      if (variable_get('taxonomy_context_node_block', TAXONOMY_CONTEXT_NODE_BLOCK_NONE) && $nodes = taxonomy_context_nodes_links($term->tid)) {
        $children .= '<ul class="menu">'. $nodes ."</ul>\n";
      }
/*  commented      if (in_array($term->tid, $parents)) {*/
        $output .= '<li class="'. ($children == '' ? 'leaf' : 'expanded') .'">'. $link . $children ."</li>\n";
/*  commented    }
      else {
        $output .= '<li class="'. ($children == '' ? 'leaf' : 'collapsed') .'">' . $link . "</li>\n";
      }*/
    }
    $output .= "</ul>\n";
  }

What is edited is that I commented out line 454 and lines 456 to 459.

If I break something with this, please let me know, since as I told before I have no php codding knowledge.

Cheers,
Mguel

PS: the only thing remaining to me to don't miss any of taxonomy_menu features is an option to "display descendants" so if I clic on the menu one catagory to have displayed besides from the nodes of that category, the nodes from its subcategories also.

lee20’s picture

Status: Reviewed & tested by the community » Needs review

Attached is a patch that adds an option for expanding menu items by default to the Taxonomy Context settings form.

Collapsed is still the default setting so applying this patch will not affect the modules behavior until you change the setting to expanded in the settings page (Administer > Site Configuration > Taxonomy Context).

The patch includes constants for masking the display setting, the added select field to the taxonomy settings form, and an additional condition that checks the display setting when rendering the menu tree.

Hope this helps!
lee20

Mguel’s picture

Assigned: Unassigned » lee20
Category: support » feature
Status: Active » Needs review

Great!

Thanks a lot lee20!

nedjo’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, looks good.

One minor suggestion, I'd slightly prefer this:


if (in_array($term->tid, $parents) || variable_get('taxonomy_context_block_display', TAXONOMY_CONTENT_BLOCK_DISPLAY_COLLAPSED) == TAXONOMY_CONTENT_BLOCK_DISPLAY_EXPANDED) {

as it's a bit clearer (I had to check why || variable_get('taxonomy_context_block_display', TAXONOMY_CONTENT_BLOCK_DISPLAY_COLLAPSED) worked, i.e., because TAXONOMY_CONTENT_BLOCK_DISPLAY_COLLAPSED is 0).

lee20’s picture

Title: Display expanded menu on context block by default » Updated Patch
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.97 KB

Good point. The way I had it was an improper use of the masks, so thanks for pointing that out!

I have removed the previous patch from my post above and the attached patch reflects this change.

nedjo’s picture

Title: Updated Patch » Display expanded menu on context block by default

Looks good, please go ahead and apply.

Please always apply patches first the HEAD version and then to relevant branches (in this case, DRUPAL-5). I'll do the same.

Note that the "issue title" is the title of the whole issue rather than the comment you're making.

lee20’s picture

Okay. I have commited to the HEAD and DRUPAL-5 branch. Please double check my commits and let me know if I should do anything different as I have only used subversion before now.

Also, would the status change be patch (ready to be ported) or fixed?

From Mguel's first post:

PS: the only thing remaining to me to don't miss any of taxonomy_menu features is an option to "display descendants" so if I clic on the menu one catagory to have displayed besides from the nodes of that category, the nodes from its subcategories also.

Mguel, I agree that this feature would be useful especially for those looking to switch from Taxonomy Menu to Taxonomy Context for the pathauto support. I'm hoping to address this and supply a patch adding this option soon.

lee20’s picture

After further review, displaying all of a terms descendants will be very difficult to implement. There is no way that I see to properly implement this directly into the module given the modules current implementation. The problem is Drupal offers no way to hook into the core taxonomy functions that render a term's default display. Currently the module prepends the term/subterm info to the top of the default term output.

With that said, a module only has the ability to append or prepend to the default taxonomy output. Taxonomy Menu accomplished this by overriding the default taxonomy output entirely which is also the reason why pathauto does not work for menu links in Taxonomy Menu.

The only reasonable chance I see for replicating the display descendants behavior is by using a View.

Mguel’s picture

Thanks again lee20 for your time, intentions and explanations.

Although the display descendant option isn't possible, is not an issue that prevents me of having replaced taxonomy_menu (I replaced it on the site I used taxonomy_menu when I could display the menu expanded)

OT: regarding having the display descendant functionality with Views, how can I make the views replace the path that is now set by taxonomy_context module?
I created the view with the same url of the "Parent Term" in question, selected Teaser list and added the filter: Published Yes + Taxonomy Terms: All of: and selected the "parent term" and its subterms. But the url directs me to the same taxonomy_context page (with Term, subterms, and nodes of the parent term only.

Cheers,
Mguel

lee20’s picture

Mguel,

Wow you beat me to it! I was going to see if I could get something going with Views I am fairly new to working with the Views module but forgot to realize that Views is a module itself so it won't have any more power to hook into the taxonomy core than any other module.

I actually need to find a solution as well for a project I am working on so I will let you know what I find. It may require a complex solution of hooking into pathauto and actually escaping/overriding the core taxonomy term pages.

For clarity purposes, I have opened a new issue specific to this issue: http://drupal.org/node/207873

lee20’s picture

Okay. I was able to configure a view to get our desired results. See http://drupal.org/node/207873

nedjo’s picture

Status: Reviewed & tested by the community » Fixed

Thanks. From a cursory glance, commits look good. One detail: we usually reference the issue in a commit like this:

Issue #192111: [description of issue/change/whatever]

where 192111 is the id of the issue node. This will produce a link to the issue in the resulting commit messages, see http://drupal.org/cvs

For status, we set to fixed now. (To be ported would be if we hadn't yet ported back to an actively maintained branch.)

lee20’s picture

This patch has been committed and is available in the 5.x-1.x-dev release.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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