In this example, the client wants all fieldsets that are closed to be pushed to the bottom and hidden in another fieldset. The idea is that we've already form_altered the important sections into an uncollapsed state. I'd like to be able to do this per role with some other configuration settings, but first need to know if it is of interest - or what it would take to be worthy. The code I'm using is:

    foreach (element_children($form_values) AS $child) {
      // Verbose test to see if the element is collapsed. might be an easier way...
      if (isset($form_values[$child]['#collapsible']) &&
          isset($form_values[$child]['#collapsed']) &&
          $form_values[$child]['#collapsible'] == TRUE &&
          $form_values[$child]['#collapsed'] == TRUE) {
        // Save the key
        $hidden[] = $child;
      }
    }
    // Create a fieldset
    $form_values['advanced_settings'] = array(
      '#type'  => 'fieldset',
      '#title' => t('Advanced settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#weight' => $form_values['submit']['#weight']-1,
    );
    // Move the sections to the "Advanced settings" area.
    foreach ($hidden AS $key) {
      $form_values['advanced_settings'][$key] = $form_values[$key];
      unset($form_values[$key]);
    }

Comments

sime’s picture

At first glance this code doesn't seem to be all that useful. However, one benefit is where you want to re-weight the entire form so that the user is not bombarded with unimportant sections. By grouping all the fields together you stop worrying about weights. I know, fairly obvious, but thought I'd mention it. :)

sime’s picture

Title: moving collapsed elements to a more discrete location » Move collapsed elements out of sight
dman’s picture

I had to do something similar (in the 4.6 days) to hide the extra 2 dozen advanced metadata fields the client required us to have but didn't want to look at.

I'm thinking of modding this module to override weighting on-the-fly. Your grouping them all into a hidden /collapsed zone is also a good thought...

The UI of your implimentation however probably needs to be a bit trickier. Shunting ALL collapsed stuff away sorta breaks things for me.

sime’s picture

hey dman, thanks for the review.

Yeah, the weighting idea is good. For example, it would be great to allow admins to see move-up/move-down buttons, and certainly I only chose this method because it was simpler to implement than that.

How does it break things for you? I'd like to re-use this code in other sites, so I'm happy and keen to make it more robust.

dman’s picture

Unfortunately when I investigated the internals of the module, I couldn't see a good way to extend the current settings.
It serializes the 'hide' flag in a most curious way, and only as a flag that's either set or non-existant.
I was hoping to add extra settings such as 'change weight to' or (in my case) 'always expand/collapse this fieldset'.
Later options are 'preset default value to' and more?

Simply, the way the settings are currently saved, there is no way to extend them. I either have to create a parallal array with my own info or re-jig the internals a lot.

If the settings array was a bit more open ... such as an entire (sparse) form array of over-ride settings that could be array-merged over top of the form, then we'd really have a powerful tool.
The current '|'-delimited pseudo serialization however is a handicap.
Drupal variables can be arrays, and don't have to be serialized by hand.

Making this happen right however is significant module rewrite. Is it worth it?

sime’s picture

Status: Active » Closed (won't fix)

No, I don't think it's worth it. Thanks for the informed review, I'll keep an eye on things and see if I can contribute more later.