function tripal_set_bundle_variable
3.x tripal.entities.api.inc | tripal_set_bundle_variable($variable_name, $bundle_id, $value) |
Save the value of a tripal variable for a given bundle.
Parameters
string $variable_name: The name of the variable as in tripal_variables.name.
int $bundle_id: The unique identfier for the bundle you want the value for.
$text $value: The value of the variable for the given bundle.
Related topics
2 calls to tripal_set_bundle_variable()
- tripal_save_title_format in tripal/
api/ tripal.entities.api.inc - Save Page Title Format for a given Tripal Entity Type.
- tripal_tripal_bundle_form_submit in tripal/
includes/ TripalBundleUIController.inc - Submit: Tripal content type edit form.
File
- tripal/
api/ tripal.entities.api.inc, line 860 - Provides an application programming interface (API) for working with TripalEntity content types (bundles) and their entities.
Code
function tripal_set_bundle_variable($variable_name, $bundle_id, $value) {
$variable = tripal_get_variable($variable_name);
if (!$variable) {
if ($variable_name === 'hide_empty_field') {
tripal_insert_variable(
'hide_empty_field',
'Structure->Tripal Content Type->edit checkbox to hide empty fields for that bundle.'
);
$variable = tripal_get_variable($variable_name);
if (!$variable) {
return FALSE;
}
}
else {
return FALSE;
}
}
// And then we need to write the new format to the tripal_bundle_variables
// table.
$record = array(
'bundle_id' => $bundle_id,
'variable_id' => $variable->variable_id,
'value' => $value,
);
// Check whether there is already a format saved.
$bundle_variable_id = db_select('tripal_bundle_variables', 'var')
->fields('var', array('bundle_variable_id'))
->condition('var.bundle_id', $record['bundle_id'])
->condition('var.variable_id', $record['variable_id'])
->execute()
->fetchField();
if ($bundle_variable_id) {
$record['bundle_variable_id'] = $bundle_variable_id;
return drupal_write_record('tripal_bundle_variables', $record, 'bundle_variable_id');
}
else {
return drupal_write_record('tripal_bundle_variables', $record);
}
}