Hi,

maybe just a minor annoyance, or a feature not yet implemented, but on my site hierarchical select menu doesn't play well with 'menu settings per content type' module. Say if on page content type i only want my user to be able to link it into primary links menu (feature provided by ctm) : if hs_menu is enabled it will show all available menus. if i disable hs_menu, the standard menu selector only shows primary links, as expected.

I see that hs_menu seems to have code to 'exclude' menus, but it only seems doable in code. Maybe some hooks for ctm could help here.

Comments

wim leers’s picture

Title: Conflict with Menu Settings per Content Type module » Menu Settings per Content Type module support for Hierarchical Select
Project: Hierarchical Select » Menu Settings per Content Type
Version: 6.x-3.x-dev » 6.x-1.x-dev
Component: Code - Menu » Code
Category: bug » feature

This is not a bug, it's a feature request.

It's likely that that module is simply overriding the menu settings for each node type, and that HS is then overriding it again. Welcome to the wonderful world of hooks :)

Let's move this to the Menu Settings per Content Type module to get some feedback on how it works.

jglynn’s picture

I'm seeing this problem too. Any chance of getting these two modules to work together?

sos4nt’s picture

Wim is right. Both modules get the menu data from the database to rebuild the menu settings from scratch.

no2e’s picture

Issue tags: +hierarchical_select

I'd love to see both modules (ctm and hierarchical_select) work together. Any chance?

nullpainter’s picture

Hi guys,

It's quite easy to see why the two don't play ball - in hook_form_alter() for CTM, $form['menu']['parent']['#options'] is set, and in the same for hs_menu, $form['menu']['parent']['#options'] is unset ;-)

Wim - I'm not proposing for one moment to change hierarchical select as, you rightly say, it's not your problem. However, it would be really useful to expose hooks that allow other modules to play nicely with you if they so desire. Would this be a major undertaking to add hooks at places deemed useful, or am I oversimplifying the issue? It may save you from quite so many 'Module XYZ is broken with hierarchical select' type requests...

For the problem at hand, modifying the behaviour of hs_menu_hierarchical_select_root_level() initially seems appropriate, however we need the current form in scope to work out the selected CTM menus so it all gets a bit nightmare-ish unless one is prepared to do significant hacking of hierarchical select, which seems to be a really dumb thing to even consider doing.

M

nullpainter’s picture

My previous comment aside, I have managed with very small effort to get CTM and hierarchical select to play nicely.

However, there is a large caveat - the code is a hack, as it requires modifying the hierarchical select module. I therefore don't recommend it unless you are able to justify to yourself that hacking with module code is fine and that you promise not to bug Wim if it inadvertently breaks anything.

This being said, if you change the following in hierarchical_select.module:

1. From:

function _hierarchical_select_hierarchy_generate($config, $selection, $required, $dropbox = FALSE) {

to:

function _hierarchical_select_hierarchy_generate($config, $selection, $required, $dropbox = FALSE, $form = null) {

2. From:

$hierarchy = _hierarchical_select_hierarchy_generate($config, $hs_selection, $element['#required'], $dropbox);

to:

$hierarchy = _hierarchical_select_hierarchy_generate($config, $hs_selection, $element['#required'], $dropbox, $form);

3. From:

// Start building the levels, initialize with the root level.
$hierarchy->levels[0] = module_invoke($config['module'], 'hierarchical_select_root_level', $config['params']);

to:

 // Start building the levels, initialize with the root level.
  $hierarchy->levels[0] = module_invoke($config['module'], 'hierarchical_select_root_level', $config['params']);
  
  $updated_parent_menu = module_invoke_all('alter_parent_menu', $form, $hierarchy->levels[0]);
  if (!empty($updated_parent_menu)) {
  	$hierarchy->levels[0] = $updated_parent_menu;	
  } 

and add the following hook in a module (changing 'my_module' to be the name of your module):


function my_module_alter_parent_menu(&$form, &$parent_menu) {
	$menu_settings = variable_get($form['#node']->type.'_menu_settings', array());

	$target_menu = array();
	foreach ($parent_menu as $key => $title) {
			
		$parent_menu_name = substr($key, 0, strpos($key, ':'));
		if (in_array($parent_menu_name, $menu_settings)) {
			$target_menu[$key] = $title;
		}
	}

	return $target_menu;
}

then the parent menu items rendered in hierarchical select will be sourced from the array returned by the hook instead of the default list returned in hs_menu_hierarchical_select_root_level().

As per my comments at the start of this message, please consider this a proof of concept rather than a recommended fix. Implementation of formal hooks to be able to tweak this, as per my previous message, would of course be ideal.

M

jabraben’s picture

Subscribe

izkreny’s picture

+1 for #5.

It's really fascinating how many good and useful menu modules is out there, and how little of them can actually work together. :(

summit’s picture

Subscribing, greetings, Martijn

vasike’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev

moved to the new branch

Pepper’s picture

Has this been integrated into the new branch, or is HS still overriding? Unfortunately the fix that was posted isn't good for the current version of HS (6.x)

vasike’s picture

Issue summary: View changes
Status: Active » Closed (outdated)