function matrix_settings_throbber_callback_form in Matrix field 6.2
Form definition for the throbber This list is called when a new field is added via the settings page or a field is edited
Return value
form definition
File
- ./
admin.inc, line 177 - Provides functions used in the creation of matrix fields.
Code
function matrix_settings_throbber_callback_form($form_state) {
$field_name = $form_state['post']['field_name'];
$field_type = $form_state['post']['field_type'];
$rc = $form_state['post']['rc'];
$mode = $form_state['post']['mode'];
if ($form_state['post']['element_id'] != 'undefined') {
$element_id = $form_state['post']['element_id'];
$cache_response = cache_get('matrix-' . $rc . '-' . $field_name);
//load existing elements from cache
$elements = (array) $cache_response->data;
$default_values = $elements[$element_id];
}
if (!empty($form_state['post']['element_type']) && $form_state['post']['element_type'] != 'undefined') {
$element_type = $form_state['post']['element_type'];
}
else {
$element_type = $default_values['#type'];
}
$form['element'] = array(
'#type' => 'fieldset',
'#title' => t('add/edit'),
);
$form['element']['element_id'] = array(
'#type' => 'hidden',
'#value' => $element_id,
'#attributes' => array(
'class' => "matrix-{$rc}",
),
);
if ($mode == $rc || $field_type == 'table') {
$options = array(
'' => t('- select -'),
'title' => t('Title only'),
'textfield' => t('Textfield'),
'select' => t('Select'),
'checkbox' => t('Checkbox'),
'radios' => t('Radio buttons'),
'calculation' => t('Calculation'),
);
}
else {
$options = array(
'' => t('- select -'),
'title' => t('Title only'),
);
}
$form['element']['element_type'] = array(
'#type' => 'select',
'#options' => $options,
'#title' => t('Widget type'),
'#attributes' => array(
'class' => "matrix-{$rc}",
),
'#default_value' => $element_type,
);
if (!empty($element_type)) {
//a widget type has been chosen - render some more form
$form['element']['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#size' => 10,
'#default_value' => $default_values['#title'],
'#attributes' => array(
'class' => "matrix-{$rc}",
),
);
switch ($element_type) {
case 'textfield':
$form['element']['size'] = array(
'#type' => 'textfield',
'#title' => t('Size'),
'#size' => 5,
'#default_value' => !empty($default_values['#size']) ? $default_values['#size'] : 5,
'#attributes' => array(
'class' => "matrix-{$rc}",
),
);
$form['element']['validation'] = array(
'#type' => 'select',
'#title' => t('Validation'),
'#options' => array(
'none' => t('None'),
'numeric' => t('Numeric'),
'custom' => t('Custom'),
),
'#default_value' => !empty($default_values['#validation']) ? $default_values['#validation'] : 5,
'#attributes' => array(
'class' => "matrix-{$rc}",
),
);
break;
case 'select':
case 'radios':
$form['element']['options'] = array(
'#type' => 'textarea',
'#title' => t('Options'),
'#description' => t('One option per line.'),
'#cols' => 20,
'#rows' => 6,
'#default_value' => $default_values['#options'],
'#attributes' => array(
'class' => "matrix-{$rc}",
),
);
if (user_access('use php for matrix options')) {
$form['element']['php'] = array(
'#type' => 'checkbox',
'#title' => t('Evaluate as php'),
'#description' => t('Tick to evaluate the contents of the options box as php. Note do not include <?php ?> tags.'),
'#default_value' => $default_values['#php'],
'#attributes' => array(
'class' => "matrix-{$rc}",
),
);
}
break;
case 'calculation':
$form['element']['calc_method'] = array(
'#type' => 'select',
'#title' => t('Calculation type'),
'#options' => array(
'select' => t('- select one -'),
'sum' => t('Sum'),
'average' => t('Average'),
'max' => t('Maximum'),
'min' => t('Minimum'),
'max' => t('Maximum'),
'mode' => t('Most common'),
),
'#description' => t('The calculation type. Note that apart from "Most common" the other calculation types require numeric data.'),
'#default_value' => $default_values['#calc_method'],
'#attributes' => array(
'class' => "matrix-{$rc}",
),
);
break;
case 'checkbox':
case 'title':
break;
}
$form['element']['required'] = array(
'#type' => 'checkbox',
'#title' => t('Required'),
'#default_value' => $default_values['#required'],
'#attributes' => array(
'class' => "matrix-{$rc}",
),
);
$form['element']['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#attributes' => array(
'class' => "matrix-{$rc}",
),
);
$form['element']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
'#attributes' => array(
'class' => "matrix-{$rc}",
),
);
$form['element']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#attributes' => array(
'class' => "matrix-{$rc}",
),
);
}
return $form;
}