You are here

function views_calc_fields_form in Views Calc 7

Same name and namespace in other branches
  1. 5 views_calc.module \views_calc_fields_form()
  2. 6.3 views_calc.module \views_calc_fields_form()
  3. 6 views_calc.module \views_calc_fields_form()

FAPI fields_form.

Views Calc Fields tab on views list.

2 string references to 'views_calc_fields_form'
views_calc_import_form_submit in ./views_calc.module
FAPI import_form submit.
views_calc_menu in ./views_calc.module
Implements hook_menu().

File

./views_calc.module, line 199
This module will allow you to add calculated fields to views tables and compute (SUM, COUNT, AVG, etc) columns of numeric data in a views table.

Code

function views_calc_fields_form($form, &$form_state) {
  $i = 0;
  $substitutions = array();
  $help = t('<p>The specific fields that are available in any view depend on the base table used for that view.</p>');
  require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'views') . '/includes/admin.inc';
  $base_tables = views_fetch_base_tables();
  foreach ($base_tables as $base => $data) {
    $base_subs = _views_calc_substitutions($base);
    $substitutions += $base_subs;
    $fieldset = array(
      '#title' => t('Base table: !name', array(
        '!name' => t($data['title']),
      )),
      '#value' => theme('item_list', array(
        'items' => $base_subs,
      )),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#attributes' => array(),
      '#children' => '',
    );
    $help .= theme('fieldset', array(
      'element' => $fieldset,
    ));
  }

  // display current views calcs fields
  $fields = _views_calc_fields();
  foreach ($fields as $field) {
    $form[] = views_calc_field_form_item($i, $field, $substitutions);
    $i++;
  }

  // add blank fields for more calcs
  for ($x = $i + 1; $x < $i + 2; $x++) {
    $field = array();
    $form[] = views_calc_field_form_item($i, $field, $substitutions);
  }
  $form['#prefix'] = '<div class="views-calc-field-settings">';
  $form['#suffix'] = '</div><div class="views-calc-field-names"><strong>Field Substitutions</strong><div class="form-item">' . $help . '</div></div>';
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}