Problem/Motivation

Currently Multistep 6.x only supports fieldsets created by the CCK Fieldgroup module. Multistep does account for extra fields exposed through hook_content_extra_fields(), but only for placement within steps, not as potential steps themselves.

Proposed resolution

I admit to not finding the cck fieldgroup angle a very flexible solution as the only way to specify multistep steps. I would probably prefer a different UI for organizing these (maybe something closer to field_group in D7, but I'm thinking this would require a lot of factoring in D6).

Instead (for D6 only) how about a hook to alter the $groups variable in _multistep_block() before the menu items are generated? Something like:

       $groups = fieldgroup_groups($type);
+      // Support non-fieldgroup steps.
+      drupal_alter('multistep_fieldgroups', $groups, $type);

API changes

This way extra fields exposed through hook_content_extra_fields() could be added as steps. Something like:

function hook_multistep_fieldgroups_alter(&$fieldgroups, $type_name) {
  // Create an array of information about our pseudo field, as if it were a
  // fieldgroup element like Multistep expects.
  $pseudo_fieldgroup = array(
    'group_name' => $extra_field_name,
    'label' => $label,
    'settings' => array(
      'multistep' => array(
        'block' => TRUE,
        'step' => $step,
      ),
    ),
    'weight' => $weight,
  );

  // Add our pseudo field to the multistep fieldgroups array.
  $fieldgroups[$extra_field_name] = $pseudo_fieldgroup;
}

Modules that implement this hook would need to add their own re-sorting function for the array – or we could add that to Multistep after the hook… Either way, something like:

// Create a new dummy array for sorting, keyed by item weight.
  $dummy = array();
  foreach($fieldgroups as $item) {
    $dummy[$item['weight']] = $item;
  }
  // Sort by key.
  ksort($dummy);

  // Recreate fieldgroups from the dummy array order, now sorted by item weight.
  $fieldgroups = array();
  foreach($dummy as $item) {
    $fieldgroups[$item['group_name']] = $item;
  }

Or we could skip the hook and add support for extra fields more generically… I just wrote some code that would work for that, but we'd need a UI to declare extra fields as steps. I'll start by adding a patch for the hook for starters… it would be good to get some feedback on whether others see this as useful before taking this too far in D6.

Comments

scottrigby’s picture

Here's that initial hook as a patch for feedback.

scottrigby’s picture

Also, here's that generic code to support extra fields (currently goes at the top of the proposed hook, and the sorting function goes at the bottom of that hook). If there's interest i could make a patch for this kind of generic support in Multistep rather than asking modules to implement the hook like this themselves.

  // Declare an extra field as a multistep block item.
  // @todo add a UI to save this setting so we can get it programmatically. 
  $extra_field_name = MY_EXTRA_FIELD;

  // Get the step number this extra field is configured to use.
  $step = variable_get('multistep_extra_'. $extra_field_name .'_'. $type_name, 1);

  // Get label and weight from hook_content_extra_fields() definition. We are
  // more or less duplicating content_extra_field_weight() here becaues we also
  // want the label.
  $weight = 0;
  $label = '';
  $type = content_types($type_name);
  if (!isset($type['extra'][$extra_field_name])) {
    content_clear_type_cache();
    $type = content_types($type_name);
  }
  if (isset($type['extra'][$extra_field_name])) {
    $weight = $type['extra'][$extra_field_name]['weight'];
    $label = $type['extra'][$extra_field_name]['label'];
  }
scottrigby’s picture

Status: Active » Needs review

Actually… after looking over 7.x-1.x, sorting is handled much better there. We could backport _multistep_cmp_group_weight()… and really a lot of the improvements in the 7.x branch could be backported to 6.x-1.x.

@vkareh or @axel.rutz – Could you use any help with that?

scottrigby’s picture

Also noting related request (for fields as steps in general): #839408: Support menu block for cck fields