function tripal_set_default_cv

2.x tripal_cv.api.inc tripal_set_default_cv($table, $field, $cv_name, $cv_id = FALSE)
3.x tripal_cv.api.inc tripal_set_default_cv($table, $field, $cv_name, $cv_id = FALSE)

This function sets the default vocabulary for a given table and field.

Parameters

$table: The name of the table that contains a field with a foreign key relationship to the cvterm table

$field: The table field name that has the foreign key relationship to the cvterm table for which the default vocabulary will be set

$cv_name: The name of the vocabulary

Return value

TRUE if set, FALSE if an error occured

23 calls to tripal_set_default_cv()
tripal_analysis_install in tripal_analysis/tripal_analysis.install
Implementation of hook_install().
tripal_analysis_update_7200 in tripal_analysis/tripal_analysis.install
This is the required update for tripal_organism when upgrading from Drupal core API 6.x.
tripal_contact_install in tripal_contact/tripal_contact.install
Implementation of hook_install().
tripal_contact_update_7200 in tripal_contact/tripal_contact.install
This is the required update for tripal_contact when upgrading from Drupal core API 6.x.
tripal_cv_admin_set_defaults_form_submit in tripal_cv/includes/tripal_cv.admin.inc

... See full list

File

tripal_cv/api/tripal_cv.api.inc, line 1044
This module provides a set of functions to simplify working with controlled vocabularies.

Code

function tripal_set_default_cv($table, $field, $cv_name, $cv_id = FALSE) {

  // Get the CV object
  if ($cv_id) {
    $cv = tripal_get_cv(array('cv_id' => $cv_id));
  }
  else {
    $cv = tripal_get_cv(array('name' => $cv_name));
  }

  if ($cv) {
    // first delete any entries for this table and field
    $num_deleted = db_delete('tripal_cv_defaults')
      ->condition('table_name', $table)
      ->condition('field_name', $field)
      ->execute();

    // now add the default value
    $cv_default_id = db_insert('tripal_cv_defaults')
      ->fields(array(
        'table_name' => $table,
        'field_name' => $field,
        'cv_id' => $cv->cv_id,
      ))
      ->execute();

    if (!$cv_default_id) {
      tripal_report_error('tripal_cv', TRIPAL_WARNING, 
      "Cannot set default vocabulary for %table.%field. Check the error logs.", 
      array('%table' => $table, '%field' => $field));
      return FALSE;
    }
  }
  else {
    tripal_report_error('tripal_cv', TRIPAL_WARNING, 
    "Cannot set default vocabulary for %table.%field. The vocabulary name, '%cvname', doesn't exist.", 
    array('%table' => $table, '%field' => $field, '%cvname' => $cv_name));
    return FALSE;
  }
}