You are here

function msnf_fields_nest in Multistep Nodeform 7

Recursive function to nest fields in the steps.

This function will take out all the elements in the form and place them in the correct container element.

Parameters

<array> $element: The current element to analyse.

1 call to msnf_fields_nest()
msnf_build_pre_render in ./msnf.module
Process callback.

File

./msnf.module, line 951
Main functions for module "Multistep Nodeform".

Code

function msnf_fields_nest(&$element) {

  // Create all steps and keep a flat list of references to these steps.
  $step_references = array();
  foreach ($element['#steps'] as $step_name => $step) {
    $element[$step_name] = array();
    $step_references[$step_name] =& $element[$step_name];
  }

  // Move all children to their parents. Use the flat list of references for
  // direct access as we don't know where in the root_element hierarchy the
  // parent currently is situated.
  foreach ($element['#step_children'] as $child_name => $parent_name) {

    // Block denied fields (#access) before they are put in groups.
    // Fields (not groups) that don't have children (like field_permissions) are removed
    // in field_group_field_group_build_pre_render_alter.
    if (isset($element[$child_name]) && (!isset($element[$child_name]['#access']) || $element[$child_name]['#access'])) {

      // If this is a group, we have to use a reference to keep the reference
      // list intact (but if it is a field we don't mind).
      $step_references[$parent_name][$child_name] =& $element[$child_name];
    }

    // The child has been copied to its parent: remove it from the root element.
    unset($element[$child_name]);
  }

  // Bring extra element wrappers to achieve a grouping of fields.
  // This will mainly be prefix and suffix altering.
  foreach ($element['#steps'] as $step_name => $step) {
    msnf_pre_render($step_references[$step_name], $step, $element);
  }
}