function taxonomy_display_save_taxonomy_display in Taxonomy display 7
Helper function; save a taxonomy display record in the database.
Parameters
string $machine_name: The machine name of the vocabulary's taxonomy display data to save.
array $save_data:
string|NULL|FALSE $watchdog_message: Provide a watchdog message as a string. If null then a generic default message will be used. If false then no watchdog message will be recorded.
array $watchdog_variables: Variables for substitution in the watchdog message.
int $watchdog_severity: One of the defined watchdog constant severities: WATCHDOG_EMERGENCY, WATCHDOG_ALERT, WATCHDOG_CRITICAL, WATCHDOG_ERROR, WATCHDOG_WARNING, WATCHDOG_NOTICE, WATCHDOG_INFO, WATCHDOG_DEBUG. Defaults to WATCHDOG_NOTICE.
Return value
void
2 calls to taxonomy_display_save_taxonomy_display()
- taxonomy_display_admin_form_submit in ./
taxonomy_display.admin.inc - Form submit callback; save Taxonomy Display settings for term pages.
- taxonomy_display_taxonomy_vocabulary_update in ./
taxonomy_display.module - Implements hook_taxonomy_vocabulary_update().
File
- ./
taxonomy_display.module, line 253 - Hooks for the taxonomy display module.
Code
function taxonomy_display_save_taxonomy_display($machine_name, $save_data = array(), $watchdog_message = NULL, $watchdog_variables = array(), $watchdog_severity = WATCHDOG_NOTICE) {
// Allow other modules to alter our fields before they are inserted/updated.
drupal_alter('taxonomy_display_save_fields', $save_data);
// Prepare the fields to be used for the insert or update query.
$query_fields = array();
foreach ($save_data as $k => $v) {
switch ($k) {
case 'machine_name':
case 'term_display_plugin':
case 'associated_display_plugin':
case 'breadcrumb_display_plugin':
case 'add_feed':
$query_fields[$k] = $v;
break;
case 'term_display_options':
case 'associated_display_options':
case 'breadcrumb_display_options':
$query_fields[$k] = serialize($v);
break;
default:
break;
}
}
// Retrieve the machine name, tells us whether to insert or update.
$update = taxonomy_display_fetch_taxonomy_display($machine_name);
// If $update was fetched from cache, CTools export.inc is not included.
ctools_include('export');
// Perform our save
try {
// If update
if (!isset($update->no_record) && $update->export_type & EXPORT_IN_DATABASE) {
// Do not proceed if there are no fields to update.
if (empty($query_fields)) {
return;
}
// Query
$count = (bool) db_update('taxonomy_display')
->fields($query_fields)
->condition('machine_name', $machine_name)
->execute();
if ($count && $watchdog_message !== FALSE) {
if (empty($watchdog_message)) {
$watchdog_message = 'Taxonomy display vocabulary data updated for %machine_name.';
$watchdog_variables = array(
'%machine_name' => $machine_name,
);
}
watchdog('taxonomy_display', $watchdog_message, $watchdog_variables, $watchdog_severity);
}
}
else {
// If the record is being inserted we do not want to force the user to
// supply machine_name twice for no reason, if they know it is an insert.
if (!isset($query_fields['machine_name'])) {
$query_fields['machine_name'] = $machine_name;
}
// Query
$value = db_insert('taxonomy_display')
->fields($query_fields)
->execute();
if ($watchdog_message !== FALSE) {
if (empty($watchdog_message)) {
$watchdog_message = 'Taxonomy display vocabulary data created for %machine_name.';
$watchdog_variables = array(
'%machine_name' => $machine_name,
);
}
watchdog('taxonomy_display', $watchdog_message, $watchdog_variables, $watchdog_severity);
}
}
} catch (Exception $e) {
drupal_set_message(t('Taxonomy display data save failed. Message = %message, query= %query', array(
'%message' => $e
->getMessage(),
'%query' => $e->query_string,
)), 'error');
}
// Clear our display settings for the machine name.
cache_clear_all('taxonomy_display:settings:' . $machine_name, 'cache');
// Regenerate the display settings for the machine name in cache so they are
// ready on the next load.
taxonomy_display_fetch_taxonomy_display($machine_name);
}