function chado_phylotree_validate

2.x tripal_phylogeny.chado_node.inc chado_phylotree_validate($node, $form, &$form_state)
3.x tripal_phylogeny.chado_node.inc chado_phylotree_validate($node, $form, &$form_state)

Implementation of hook_validate().

This validation is being used for three activities: CASE A: Update a node that exists in both drupal and chado CASE B: Synchronizing a node from chado to drupal CASE C: Inserting a new node that exists in niether drupal nor chado

Related topics

File

tripal_phylogeny/includes/tripal_phylogeny.chado_node.inc, line 346
Implements the phylotree node content type

Code

function chado_phylotree_validate($node, $form, &$form_state) {

  // We are syncing if we do not have a node ID but we do have a phylotree_id. We don't
  // need to validate during syncing so just skip it.
  if (is_null($node->nid) and property_exists($node, 'phylotree_id') and $node->phylotree_id != 0) {
    return;
  }

  // Remove surrounding white-space on submitted values.
  $node->tree_name = trim($node->tree_name);
  $node->description = trim($node->description);
  $node->dbxref = trim($node->dbxref);

  // if this is a delete then don't validate
  if ($node->op == 'Delete') {
    return;
  }

  $errors = array();
  $warnings = array();
  $options = array(
    'name' => $node->tree_name,
    'description' => $node->description,
    'analysis_id' => $node->analysis_id,
    'leaf_type' => $node->leaf_type,
    'tree_file' => $node->tree_file,
    'format' => 'newick',
    'dbxref' => $node->dbxref,
    'match' => $node->match,
    'name_re' => $node->name_re,
  );
  // If we have a node id already then this is an update:
  if ($node->nid) {
    $options['phylotree_id'] = $node->phylotree_id;
    tripal_validate_phylotree('update', $options, $errors, $warnings);
  }
  else {
    tripal_validate_phylotree('insert', $options, $errors, $warnings);
  }

  // Now set form errors if any errors were detected.
  if (count($errors) > 0) {
    foreach ($errors as $field => $message) {
      if ($field == 'name') {
        $field = 'tree_name';
      }
      form_set_error($field, $message);
    }
  }
  // Add any warnings if any were detected
  if (count($warnings) > 0) {
    foreach ($warnings as $field => $message) {
      drupal_set_message($message, 'warning');
    }
  }
}