You are here

function views_calc_field_form_item in Views Calc 5

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

A form element for an individual calculated field.

1 call to views_calc_field_form_item()
views_calc_fields_form in ./views_calc.module
Views Calc Fields tab on views list.

File

./views_calc.module, line 239
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_field_form_item($i, $field, $substitutions) {
  $form['group'][$i] = array(
    '#type' => 'fieldset',
    '#tree' => TRUE,
    '#title' => t('Field: ') . ($field['label'] ? $field['label'] : t('New')),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['group'][$i]['cid'] = array(
    '#type' => 'hidden',
    '#value' => intval($field['cid']),
  );
  $form['group'][$i]['tablelist'] = array(
    '#type' => 'hidden',
    '#value' => $field['tablelist'],
  );
  $form['group'][$i]['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Label'),
    '#field_prefix' => 'ViewsCalc: ',
    '#default_value' => str_replace('ViewsCalc: ', '', $field['label']),
    '#description' => t('The views field name for this field (i.e. Views Calc: My Calculation).'),
  );
  $form['group'][$i]['calc'] = array(
    '#type' => 'textarea',
    '#title' => t('Calculation'),
    '#default_value' => strtr($field['calc'], $substitutions),
    '#description' => t('<p>The query operation to be performed, using numbers, field substitutions, and ' . implode(' ', _views_calc_operators()) . '.</p>'),
  );
  $form['group'][$i]['format'] = array(
    '#type' => 'select',
    '#title' => t('Format'),
    '#default_value' => $field['format'],
    '#options' => drupal_map_assoc(array_keys(_views_calc_format_options())),
    '#description' => t('The format of the result of this calculation.'),
  );
  $form['group'][$i]['custom'] = array(
    '#type' => 'textfield',
    '#title' => t('Custom function'),
    '#default_value' => $field['custom'],
    '#description' => t('The function to call for a custom format.'),
  );
  return $form;
}