function tripal_core_node_toc_form_submit
2.x tripal_core.toc.inc | tripal_core_node_toc_form_submit($form, &$form_state) |
3.x tripal_core.toc.inc | tripal_core_node_toc_form_submit($form, &$form_state) |
Implements hook_submit for the tripal_core_node_toc_form.
File
- tripal_core/
includes/ tripal_core.toc.inc, line 202
Code
function tripal_core_node_toc_form_submit($form, &$form_state) {
$toc_items = $form_state['values']['toc_items'];
$node = $form_state['values']['node'];
if ($form_state['clicked_button']['#name'] == "toc_submit") {
$transaction = db_transaction();
try {
// First delete any settings for this node
db_delete('tripal_toc')
->condition('nid', $node->nid)
->execute();
// Second add in any new settings for this node
foreach ($toc_items as $toc_id => $item) {
db_insert('tripal_toc')
->fields(array(
'node_type' => $node->type,
'key' => $toc_id,
'title' => array_key_exists('title', $item) ? $item['title'] : '',
'weight' => $item['weight'],
'nid' => $node->nid,
'hide' => $item['hide'],
))
->execute();
}
drupal_set_message("TOC changes successfully applied to this node only.");
}
catch (Exception $e) {
$transaction->rollback();
drupal_set_message("Failed to apply TOC changes.", "error");
}
}
if ($form_state['clicked_button']['#name'] == "toc_unset") {
$transaction = db_transaction();
try {
// First delete any settings for this node
db_delete('tripal_toc')
->condition('nid', $node->nid)
->execute();
drupal_set_message("TOC is no longer customized specifically for this page. Now using the content type settings.");
}
catch (Exception $e) {
$transaction->rollback();
drupal_set_message("Failed to apply TOC changes.", "error");
}
}
}