The Menu Item Attributes fieldset is open by default, even when empty.

Is there a way to cause it to be closed when empty?

Comments

escoles’s picture

Version: 6.x-1.4 » 6.x-2.0-beta1

(correcting version)

escoles’s picture

Title: Menu Item Attributes Fieldset closed when empty » Make Menu Item Attributes Fieldset closed when empty?
escoles’s picture

Have been attempting to modify the collapsed status via hook_node_alter. Not sure how to reference the menu_attributes fieldset. I do know that this does NOT work:

function bc_fieldsets_form_alter(&$form, $form_state, $form_id) {
    switch ($form_id) {
      case 'page_node_form':
       $form['menu_attributes']['#collapsed'] = TRUE;
       break;  
    }
}

However, I've verified that the code should work against a top-level fieldset -- this DOES work to collapse the Menu settings fieldset:

function bc_fieldsets_form_alter(&$form, $form_state, $form_id) {
    switch ($form_id) {
      case 'page_node_form':
       $form['menu']['#collapsed'] = TRUE;
       break;  
    }
}

(This also confirms that the module weight is sufficiently high to execute after menu_attributes.)

escoles’s picture

The proper way to address the Menu Attributes fieldset is this: $form['menu']['options']['attributes']

So, you can collapse that fieldset by default by creating a custom module, as described here:

http://www.initsix.co.uk/collapse-or-expand-drupal-6-fieldsets-default

... and here:

http://drupal.org/node/708438

This is the code I used:

function <em>CLIENTNAME</EM>_fieldsets_form_alter(&$form, $form_state, $form_id) {
    switch ($form_id) {
      case 'page_node_form':
      case 'bare_node_node_form':
      case 'event_node_form':
      case 'image_node_form':
      case 'media_coverage_node_form':
      case 'news_item_node_form':
      case 'news_release_node_form':
      case 'composite_layout_page_node_form':
      case 'job_node_form':
      case 'question_answer_node_form':
      case 'simple_node_node_form':
      case 'story_node_form':
      case 'webform_node_form':
      case 'white_paper_node_form':
       $form['menu']['options']['attributes']['#collapsed'] = TRUE;
       break;  
    }
}

Still would make a lot more sense to me for this module to be collapsed when no attributes have been set. It takes up easily 2/3 of the vertical space in the browser window of the 1024px-high screen I'm using right now.

escoles’s picture

Issue tags: +collapsible fieldset
TimeBandit’s picture

This works in menu section (admin/build/menu) but I can't seem to affect node/add pages...

function yourModuleName_form_alter(&$form, $form_state, $form_id) {
 
  // make menu attributes field collapsed by default
    switch ($form_id) {
      default:
       $form['menu']['options']['attributes']['#collapsed'] = TRUE;
       break; 
    }
 
}

ehhh... my coding powers near zero, I chickened out and just used JQuery:
$("legend:contains('Menu item attributes')").parent().addClass('collapsed');

jimmynash’s picture

I think this approach works using the default in the switch. I had to make my custom module a little heavier than the menu_attributes module. It had a weight of 10, I made my module weight 11 and was able to get this to work across the site.

ParisLiakos’s picture

Version: 6.x-2.0-beta1 » 7.x-1.x-dev
Status: Active » Fixed
Issue tags: -collapsible fieldset

For drupal 7 do this:

/**
 * Implements hook_form_FORM_ID_alter() for menu_edit_item.
 */
function MODULENAME_form_menu_edit_item_alter(&$form, &$form_state) {
  drupal_add_js("jQuery(document).ready(function () {jQuery('#edit-options-attributes a.fieldset-title').trigger('click');})", 'inline');
}

and dont mess with module weights...much simpler

Status: Fixed » Closed (fixed)

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

mikelaroy’s picture

I created a module based on the last post, but haven't got around to packaging it up properly.

You can find the module here.