1

In Drupal 7, several modules on the user edit page provide options in collapsible fieldsets (I think this is the right word-- you can click the title above the option and the area containing the option will "collapse" and fold up).

For example, * timezone (Core) * whether to receive e-mail notifications upon receipt of messages from other members (privatemsg) * disable HTML mail (mimemail)

However, I would prefer to have the titles of these options to be regular titles (i.e., even if you click them, they don't collapse; nothing happens). How can I override this behavior?

I tried the following code based on this question:

function mymodule_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
    $form['timezone']['#collapsible'] = FALSE;
}

However, after clearing my cache, the timezone field is still collapsible on the user edit page.

EDIT: I had accidentally called form_user_profile_form_alter twice. Consolidating the two overrides fixed my problem.

2

The easier way is to set the #collapsible property to FALSE.
As far as I know, when #collapsible is set to FALSE, #collapsed is not used anymore, which means the fieldsets are shown as visible; if that is not the case, then set also #collapsed to FALSE.

Clearly, this works only for fieldsets; for other form fields, those properties are not used.

As side note, on Drupal 8 collapsible fieldsets are implemented using "details" as form field (at least from the Drupal core code); if you are going to loop through the elements of a form to check for which ones the property should be set, the code should be similar to the following one, for Drupal 8.

foreach (element_children($form) as $id) {
  if (!empty($form[$id]) && ($form[$id]['#type'] == 'details' || $form[$id]['#type'] == 'fieldset')) {
    $form[$id]['#collapsible'] = FALSE;
    $form[$id]['#collapsed'] = FALSE;
  }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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