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.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | multistep-support-non-fieldgroup-steps-1381012-1.patch | 893 bytes | scottrigby |
Comments
Comment #1
scottrigbyHere's that initial hook as a patch for feedback.
Comment #2
scottrigbyAlso, 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.
Comment #3
scottrigbyActually… 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?
Comment #4
scottrigbyAlso noting related request (for fields as steps in general): #839408: Support menu block for cck fields