function chado_add_node_form_relationships_add_button_submit

2.x tripal_core.chado_nodes.relationships.api.inc chado_add_node_form_relationships_add_button_submit($form, &$form_state)

Called by the add button in chado_add_node_form_relationships

Create an array of additional relationships in the form state. This array will then be used to rebuild the form in subsequent builds

Related topics

1 call to chado_add_node_form_relationships_add_button_submit()
chado_add_node_form_subtables_add_button_submit in tripal_core/api/tripal_core.chado_nodes.api.inc
Add subtable entries to the node forms. Supported subtables: Properties, Relationships, Additional DBxrefs.

File

tripal_core/api/tripal_core.chado_nodes.relationships.api.inc, line 732
API to manage the chado _relationship table for various Tripal Node Types

Code

function chado_add_node_form_relationships_add_button_submit($form, &$form_state) {


  $details = unserialize($form_state['values']['relationship_table']['details']);

  // if the chado_relationships array is not set then this is the first time modifying the
  // relationship table. this means we need to include all the relationships from the db
  if (!isset($form_state['chado_relationships'])) {
    chado_add_node_form_relationships_create_relationship_formstate_array($form, $form_state);
  }

  $name = (isset($form_state['node']->{$details['base_table']}->uniquename)) ? $form_state['node']->{$details['base_table']}->uniquename : 'CURRENT';

  // get details for the new relationship
  if ($form_state['values']['relationship_table']['new']['subject_is_current']) {
    $relationship = array(
      'type_id' => $form_state['values']['relationship_table']['new']['type_id'],
      'type_name' => $form_state['values']['relationship_table']['new']['type_name'],
      'object_id' => $form_state['values']['relationship_table']['new']['object_id'],
      'object_name' => $form_state['values']['relationship_table']['new']['object_name'],
      'subject_id' => $form_state['node']->{$details['base_table']}->{$details['base_foreign_key']},
      'subject_name' => $name,
      'rank' => NULL,
      'relationship_id' => 'TEMP' . uniqid()
    );
    // we don't want the new element to pick up the values from the previous element so wipe them out
    unset($form_state['input']['relationship_table']['new']['object_id']);
    unset($form_state['input']['relationship_table']['new']['object_name']);
  }
  else {
    $relationship = array(
      'type_id' => $form_state['values']['relationship_table']['new']['type_id'],
      'type_name' => $form_state['values']['relationship_table']['new']['type_name'],
      'object_id' => $form_state['node']->{$details['base_table']}->{$details['base_foreign_key']},
      'object_name' => $name,
      'subject_id' => $form_state['values']['relationship_table']['new']['subject_id'],
      'subject_name' => $form_state['values']['relationship_table']['new']['subject_name'],
      'rank' => NULL,
      'relationship_id' => 'TEMP' . uniqid(),
    );
    // we don't want the new element to pick up the values from the previous element so wipe them out
    unset($form_state['input']['relationship_table']['new']['subject_id']);
    unset($form_state['input']['relationship_table']['new']['subject_name']);
  }

  $key = $relationship['type_id'] . '-' . $relationship['relationship_id'];
  $form_state['chado_relationships'][$key] = (object) $relationship;

  // we don't want the new element to pick up the values from the previous element so wipe them out
  unset($form_state['input']['relationship_table']['new']['type_id']);
  unset($form_state['input']['relationship_table']['new']['type_name']);
}