You are here

function msnf_steps in Multistep Nodeform 6

Same name and namespace in other branches
  1. 7 includes/msnf.steps.inc \msnf_steps()

Returns all steps for a content type.

Return value

<array> All steps including associated fields in a structured array.

14 calls to msnf_steps()
msnf_locale_refresh in ./msnf.module
Refresh strings.
msnf_prepare_form_step in ./msnf.module
Function to prepare the current form step and to alter the node form.
msnf_save_step in includes/msnf.steps.inc
msnf_step_edit_form in includes/msnf.admin.inc
Menu callback to provide a form for editing a single step.
msnf_step_features_export_options in includes/msnf.features.inc
Implementation of hook_features_export_options().

... See full list

File

includes/msnf.steps.inc, line 13

Code

function msnf_steps($content_type = '', $sorted = FALSE, $reset = FALSE) {
  global $language;
  static $steps, $steps_sorted;
  if (!isset($steps) || $reset) {
    if (($cached = cache_get('msnf_step_data:' . $language->language)) !== 0 && !empty($cached->data) && time() < $cached->expire) {

      // There is cached data available that is not expired yet.
      $data = $cached->data;
      $steps = $data['steps'];
      $steps_sorted = $data['steps_sorted'];
    }
    else {
      $result = db_query('SELECT * FROM {msnf_step} ORDER BY weight, step_name');
      $steps = array();
      $steps_sorted = array();
      while ($step = db_fetch_array($result)) {
        $step['settings'] = unserialize($step['settings']);
        $step['fields'] = array();
        $step['groups'] = array();

        // Translate strings used in this step.
        _msnf_i18nstrings_step_translate($step);

        // Load non-CCK fields and add them to the list.
        $extra_fields = msnf_extra_fields($step['type_name']);
        $step_fields = msnf_step_get_fields($step['type_name'], $step['step_name']);
        foreach ($extra_fields as $field_name => $field) {
          if (isset($step_fields[$field_name])) {

            // We do not have a real widget here but this doesn't matter.
            $field_strings = array(
              'widget_label' => $field['label'],
              'widget_description' => $field['description'],
            );

            // Allow external modules to translate field strings
            // (using hook_content_field_strings()!).
            drupal_alter('content_field_strings', $field_strings, $field['type_name'], $field_name);
            $field['label'] = $field_strings['widget_label'];
            $field['description'] = $field_strings['widget_description'];
            $step['fields'][$field_name] = $field;
          }
        }
        $steps[$step['type_name']][$step['step_name']] = $step;
        $steps_sorted[$step['type_name']][] =& $steps[$step['type_name']][$step['step_name']];
      }

      // Load fields from content.module (if installed).
      if (module_exists('content')) {
        $result = db_query('SELECT nfi.*, ms.step_name FROM {msnf_step} ms ' . 'INNER JOIN {msnf_step_fields} msf ON msf.type_name = ms.type_name AND msf.step_name = ms.step_name ' . 'INNER JOIN {' . content_instance_tablename() . '} nfi ON nfi.field_name = msf.field_name AND nfi.type_name = msf.type_name ' . 'WHERE nfi.widget_active = 1 ORDER BY nfi.weight');
        while ($field = db_fetch_array($result)) {
          $field_strings = array(
            'widget_label' => $field['label'],
            'widget_description' => $field['description'],
          );

          // Allow external modules to translate field strings
          // (using hook_content_field_strings()!).
          drupal_alter('content_field_strings', $field_strings, $field['type_name'], $field['field_name']);
          $field['label'] = $field_strings['widget_label'];
          $field['description'] = $field_strings['widget_description'];
          $steps[$field['type_name']][$field['step_name']]['fields'][$field['field_name']] = $field;
        }
      }

      // Load fieldgroups from fieldgroup.module (if installed).
      if (module_exists('fieldgroup')) {
        $result = db_query('SELECT cg.*, ms.step_name FROM {msnf_step} ms ' . 'INNER JOIN {msnf_step_fields} msf ON msf.type_name = ms.type_name AND msf.step_name = ms.step_name ' . 'INNER JOIN {' . fieldgroup_tablename() . '} cg ON cg.group_name = msf.field_name AND cg.type_name = msf.type_name ' . 'ORDER BY cg.weight');
        while ($group = db_fetch_array($result)) {
          $group_strings = array(
            'widget_label' => $group['label'],
            'widget_description' => $group['description'],
          );

          // Allow external modules to translate field strings
          // (using hook_content_field_strings()!).
          drupal_alter('content_field_strings', $group_strings, $group['type_name'], $group['group_name']);
          $group['label'] = $group_strings['widget_label'];
          $group['description'] = $group_strings['widget_description'];
          $steps[$group['type_name']][$group['step_name']]['groups'][$group['group_name']] = $group;
        }
      }
      cache_set('msnf_step_data:' . $language->language, array(
        'steps' => $steps,
        'steps_sorted' => $steps_sorted,
      ));
    }
  }
  if (empty($content_type)) {
    return $steps;
  }
  elseif (empty($steps) || empty($steps[$content_type])) {
    return array();
  }
  return $sorted ? $steps_sorted[$content_type] : $steps[$content_type];
}