You are here

function _msnf_hide_fields in Multistep Nodeform 6

Same name and namespace in other branches
  1. 7 msnf.module \_msnf_hide_fields()

Hide all fields that are not associated to the current step.

1 call to _msnf_hide_fields()
msnf_prepare_form_step in ./msnf.module
Function to prepare the current form step and to alter the node form.

File

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

Code

function _msnf_hide_fields(&$form, $form_state) {
  if (!is_array($form) || !is_array($form_state)) {
    return;
  }

  // Load necessary functions for form steps.
  module_load_include('inc', 'msnf', 'includes/msnf.steps');

  // Get node type and current step.
  $type = $form['#node']->type;
  $current_step = _msnf_form_step_get_current($form_state) - 1;

  // Get a sorted list of all steps for this content type.
  $steps = msnf_steps($type, TRUE);
  if (count($steps) == 0) {

    // No steps defined.
    return;
  }
  if (!isset($steps[$current_step])) {
    drupal_set_message(t('Invalid step index "%current_step".', array(
      '%current_step' => $current_step,
    )), 'error');
    return;
  }
  $step = $steps[$current_step];
  $type_info = msnf_content_types($type);

  // Remove non-CCK fields.
  foreach ($type_info['extra'] as $field_name => $field) {
    if (!isset($step['fields'][$field_name])) {
      unset($form[$field_name]);
    }
  }

  // Remove CCK fields (if there are some).
  foreach ($type_info['fields'] as $field_name => $field) {
    if (!isset($step['fields'][$field_name])) {
      unset($form[$field_name]);
    }
  }

  // Remove fieldgrouss (if there are some).
  if (module_exists('fieldgroup')) {
    foreach (fieldgroup_groups($type) as $group_name => $group) {
      if (!isset($step['groups'][$group_name])) {
        unset($form[$group_name]);
      }
    }
  }
}