function tripal_core_content_type_toc_form_submit

2.x tripal_core.toc.inc tripal_core_content_type_toc_form_submit($form, &$form_state)
3.x tripal_core.toc.inc tripal_core_content_type_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 768

Code

function tripal_core_content_type_toc_form_submit($form, &$form_state) {
  $toc_items = $form_state['values']['toc_items'];
  $content_type = $form_state['values']['content_type'];

  if ($form_state['clicked_button']['#name'] == "toc_submit") {
    $transaction = db_transaction();
    try {
      // First delete any settings for this content type
      db_delete('tripal_toc')
        ->condition('node_type', $content_type)
        ->isNull('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' => $content_type,
            'key' => $toc_id,
            'title' => $item['title'],
            'weight' => $item['weight'],
            'hide' => $item['hide'],
          ))
          ->execute();
      }
      drupal_set_message("TOC changes successfully applied to this content type.");
    }
    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('node_type', $content_type)
        ->isNull('nid')
        ->execute();

      drupal_set_message("The TOC is reset to defaults for this content type.");
    }
    catch (Exception $e) {
      $transaction->rollback();
      drupal_set_message("Failed to apply TOC changes.", "error");
    }
  }
}