function chado_contact_node_form_add_new_props
1.x tripal_contact.form.inc | chado_contact_node_form_add_new_props(&$form, $form_state, &$d_properties, &$d_removed) |
1 call to chado_contact_node_form_add_new_props()
- chado_contact_form in tripal_contact/
includes/ tripal_contact.form.inc - Implementation of tripal_contact_form().
File
- tripal_contact/
includes/ tripal_contact.form.inc, line 225
Code
function chado_contact_node_form_add_new_props(&$form, $form_state, &$d_properties, &$d_removed) {
// first, add in all of the new properties that were added through a previous AHAH callback
$j = 0;
$num_properties++;
// we need to find the
if ($form_state['values']) {
foreach ($form_state['values'] as $element_name => $value) {
if (preg_match('/new_value-(\d+)-(\d+)/', $element_name, $matches)) {
$new_id = $matches[1];
$rank = $matches[2];
// skip any properties that the user requested to delete through a previous
// AHAH callback or through the current AHAH callback
if ($d_removed["$new_id-$rank"]) {
continue;
}
if ($form_state['post']['remove-' . $new_id . '-' . $rank]) {
$d_removed["$new_id-$rank"] = 1;
continue;
}
// get this new_id information
$cvterm = tripal_core_chado_select('cvterm', array('name', 'definition'), array('cvterm_id' => $new_id));
// add it to the $d_properties array
$d_properties[$new_id][$rank]['name'] = $cvterm->name;
$d_properties[$new_id][$rank]['id'] = $new_id;
$d_properties[$new_id][$rank]['value'] = $value;
$d_properties[$new_id][$rank]['definition'] = $cvterm->definition;
$num_properties++;
// determine how many rows we need in the textarea
$rows = 1;
// add the new fields
$form['properties']['new'][$new_id][$rank]["new_id-$new_id-$rank"] = array(
'#type' => 'item',
'#value' => $cvterm[0]->name
);
$form['properties']['new'][$new_id][$rank]["new_value-$new_id-$rank"] = array(
'#type' => 'textarea',
'#default_value' => $value,
'#cols' => 50,
'#rows' => $rows,
'#description' => $cvterm->definition,
);
$form['properties']['new'][$new_id][$rank]["remove-$new_id-$rank"] = array(
'#type' => 'image_button',
'#value' => t('Remove'),
'#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
'#ahah' => array(
'path' => "tripal_contact/properties/minus/$new_id/$rank",
'wrapper' => 'tripal-contact-edit-properties-table',
'event' => 'click',
'method' => 'replace',
),
'#attributes' => array('onClick' => 'return false;'),
);
}
}
}
// second add in any new properties added during this callback
if ($form_state['post']['add']) {
$new_id = $form_state['values']['new_id'];
$new_value = $form_state['values']['new_value'];
// get the rank by counting the number of entries
$rank = count($d_properties[$new_id]);
// get this new_id information
$cvterm = tripal_core_chado_select('cvterm', array('name', 'definition'), array('cvterm_id' => $new_id));
// add it to the $d_properties array
$d_properties[$new_id][$rank]['name'] = $cvterm->name;
$d_properties[$new_id][$rank]['id'] = $new_id;
$d_properties[$new_id][$rank]['value'] = $value;
$d_properties[$new_id][$rank]['definition'] = $cvterm->definition;
$num_properties++;
// determine how many rows we need in the textarea
$rows = 1;
if (preg_match('/Abstract/', $cvterm[0]->name)) {
$rows = 10;
}
if ($cvterm[0]->name == 'Authors') {
$rows = 2;
}
// add the new fields
$form['properties']['new'][$new_id][$rank]["new_id-$new_id-$rank"] = array(
'#type' => 'item',
'#value' => $cvterm[0]->name
);
$form['properties']['new'][$new_id][$rank]["new_value-$new_id-$rank"] = array(
'#type' => 'textarea',
'#default_value' => $new_value,
'#cols' => 50,
'#rows' => $rows,
'#description' => $cvterm->definition,
);
$form['properties']['new'][$new_id][$rank]["remove-$new_id-$rank"] = array(
'#type' => 'image_button',
'#value' => t('Remove'),
'#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
'#ahah' => array(
'path' => "tripal_contact/properties/minus/$new_id/$rank",
'wrapper' => 'tripal-contact-edit-properties-table',
'event' => 'click',
'method' => 'replace',
),
'#attributes' => array('onClick' => 'return false;'),
);
}
return $num_properties;
}