You are here

function document_add_type in Document 6

Same name and namespace in other branches
  1. 7 document.callback.inc \document_add_type()
  2. 8.x document.callback.inc \document_add_type()
1 string reference to 'document_add_type'
document_menu in ./document.module
Implementation of hook_menu().

File

./document.callback.inc, line 90

Code

function document_add_type() {
  try {
    _document_headers();
    _document_validate_token();
    $type = $_REQUEST['type'];
    if (!isset($type)) {
      die(t('Invalid input.'));
    }
    $types = document_get_types(FALSE);
    if (array_key_exists($type, $types)) {
      die(t('The specified Document Type already exists.'));
    }
    $obj = array(
      'tid' => '',
      'vid' => document_get_vocid(),
      'name' => $type,
      'description' => '',
      'weight' => 0,
    );
    drupal_write_record('term_data', $obj);
    $hier = array(
      'tid' => $obj['tid'],
      'parent' => 0,
    );
    drupal_write_record('term_hierarchy', $hier);
    cache_clear_all();
    cache_clear_all('document_types', 'cache');
    die($obj['tid']);
  } catch (Exception $e) {
    die($e
      ->getMessage() + "\n" + $e
      ->getTraceAsString());
  }
}