function tripal_bulk_loader_set_constants_form
2.x tripal_bulk_loader.constants.inc | tripal_bulk_loader_set_constants_form($form, &$form_state, $node) |
3.x tripal_bulk_loader.constants.inc | tripal_bulk_loader_set_constants_form( |
1.x tripal_bulk_loader.constants.inc | tripal_bulk_loader_set_constants_form($form_state, $node) |
Set constants (exposed fields in template)
Parameters
$form_state: The current state of the form
$node: The node to set constants for
Return value
A form array to be rendered by drupal_get_form()
Related topics
1 string reference to 'tripal_bulk_loader_set_constants_form'
- tripal_bulk_loader_theme in tripal_bulk_loader/
tripal_bulk_loader.module - Implements hook_theme
File
- tripal_bulk_loader/
includes/ tripal_bulk_loader.constants.inc, line 123 - @todo Add file header description
Code
function tripal_bulk_loader_set_constants_form($form_state, $node) {
$form = array();
$form['nid'] = array(
'#type' => 'hidden',
'#value' => $node->nid
);
if (!tripal_bulk_loader_has_exposed_fields($node)) {
return $form;
}
$form['exposed_array'] = array(
'#type' => 'hidden',
'#value' => serialize($node->exposed_fields),
);
$form['exposed_fields'] = array(
'#type' => 'fieldset',
'#title' => t('Constant Values'),
'#collapsible' => TRUE,
'#collapsed' => ($node->template_id) ? FALSE : TRUE,
'#prefix' => '<div id="set-constants">',
'#suffix' => '</div>',
);
// Display table of already added constant sets with the ability to re-arrange and delete
$first_constant = reset($node->constants);
if (sizeof($node->constants) > 0 AND !empty($first_constant)) {
$form['exposed_fields']['explanation-1'] = array(
'#type' => 'item',
'#value' => t('You have already added constants to this bulk loading job. Each '
. 'row in the following table represents a set of constants. Each set will be used '
. 'to load your data file with the specified template resulting in the each record '
. 'in the template to be loaded x number of times where there are x sets of '
. 'constants (rows in the following table).')
);
$form['exposed_fields']['existing'] = array(
'#tree' => TRUE,
);
foreach ($node->constants as $set) {
foreach ($set as $record) {
foreach ($record as $field) {
$index = $field['record_id'] . '-' . $field['field_id'];
$group = $field['group_id'];
$form['exposed_fields']['existing'][$group][$index] = array(
'#type' => 'markup',
'#value' => filter_xss($field['value']),
);
}
}
$form['exposed_fields']['existing'][$group]['delete'] = array(
'#type' => 'markup',
'#value' => filter_xss(l(t('Edit'), 'node/' . $node->nid . '/constants/' . $group . '/edit') . ' | ' .
l(t('Delete'), 'node/' . $node->nid . '/constants/' . $group . '/delete')),
);
}
}
$form['exposed_fields']['new'] = array(
'#type' => 'fieldset',
'#title' => t('New set of Constants'),
);
$form['exposed_fields']['new']['explanation-2'] = array(
'#type' => 'item',
'#value' => t('The following fields are constants in the selected template that you need to set values for.')
);
// Add textifelds for exposed fields of the current template
$exposed_fields = FALSE;
$indexes = array();
if (tripal_bulk_loader_has_exposed_fields($node)) {
foreach ($node->exposed_fields as $exposed_index) {
$record_id = $exposed_index['record_id'];
$field_id = $exposed_index['field_id'];
$field = $node->template->template_array[$record_id]['fields'][$field_id];
if ($field['exposed']) {
$exposed_fields = TRUE;
$indexes[$record_id][] = $field_id;
switch ($field['type']) {
case 'table field':
$form['exposed_fields']['new'][$record_id . '-' . $field_id] = array(
'#type' => 'textfield',
'#title' => t('%title', array('%title' => $field['title'])),
'#description' => t('%exposed_description', array('%exposed_description' => $field['exposed_description'])),
'#default_value' => (isset($node->constants[$record_id][$field_id]['value'])) ? $node->constants[$record_id][$field_id]['value'] : $field['constant value'],
);
break;
case 'constant':
$form['exposed_fields']['new'][$record_id . '-' . $field_id] = array(
'#type' => 'textfield',
'#title' => t('%title', array('%title' => $field['title'])),
'#description' => t('Enter the case-sensitive value of this constant for your data file'),
'#default_value' => (isset($node->constants[$record_id][$field_id]['value'])) ? $node->constants[$record_id][$field_id]['value'] : $field['constant value'],
);
break;
}
$form['exposed_fields']['new'][$record_id . '-' . $field_id . '-table'] = array(
'#type' => 'hidden',
'#value' => $node->template->template_array[$record_id]['table'],
);
$form['exposed_fields']['new'][$record_id . '-' . $field_id . '-field'] = array(
'#type' => 'hidden',
'#value' => $field['field'],
);
$form['exposed_fields']['new'][$record_id . '-' . $field_id . '-type'] = array(
'#type' => 'hidden',
'#value' => $field['type'],
);
}
}
}
$form['template'] = array(
'#type' => 'hidden',
'#value' => serialize($node->template->template_array)
);
$form['exposed_fields']['new']['indexes'] = array(
'#type' => 'hidden',
'#value' => serialize($indexes),
);
if (!$exposed_fields) {
$form['exposed_fields']['new']['explanation'] = array(
'#type' => 'item',
'#value' => t('There are no exposed fields for this template.')
);
}
$form['exposed_fields']['new']['submit-2'] = array(
'#type' => 'submit',
'#name' => 'add_constant',
'#value' => t('Add Constant Set')
);
return $form;
}