function tripal_insert_variable

2.x tripal_core.tripal_variables.api.inc tripal_insert_variable($name, $description)
3.x tripal.variables.api.inc tripal_insert_variable($name, $description)

Adds a new variable name.

Parameters

$name: The name of the variable

$description: The description for the variable

Return value

A record object containg the variable that was added if successful.

Related topics

5 calls to tripal_insert_variable()
tripal_add_node_variable in legacy/tripal_core/api/tripal_core.tripal_variables.api.inc
Associates a variable and it's value to a node.
tripal_add_variables in tripal/tripal.install
Adds variables for bundles.
tripal_phylogeny_install in legacy/tripal_phylogeny/tripal_phylogeny.install
Implements hook_install().
tripal_set_bundle_variable in tripal/api/tripal.entities.api.inc
Save the value of a tripal variable for a given bundle.
tripal_update_7304 in tripal/tripal.install
Adds a variable for the bundles to manage hiding of empty fields.

File

tripal/api/tripal.variables.api.inc, line 36
Provides an application programming interface (API) for managing variables associated with Tripal managed content.

Code

function tripal_insert_variable($name, $description) {
  $name = trim($name);
  if (!$name) {
    tripal_report_error('tripal', TRIPAL_ERROR, 
    'Must have a variable name when adding a new Tripal Variable.', array());
    return NULL;
  }
  if (!$description) {
    tripal_report_error('tripal', TRIPAL_ERROR, 
    'Must have a description when adding a new Tripal Variable.', array());
    return NULL;
  }

  // Make sure the variable is not a duplicate. If so, then just select
  // it and return the variable_id
  $variable = tripal_get_variable($name);
  if ($variable) {
    return $variable;
  }
  else {
    db_insert('tripal_variables')
      ->fields(array(
        'name' => $name,
        'description' => $description,
      ))
      ->execute();
    return tripal_get_variable($name);
  }
}