node_type_save

5 node.module node_type_save($info)
6 node.module node_type_save($info)
7 node.module node_type_save($info)
8 node.module node_type_save($info)

Saves a node type to the database.

Parameters

$info: The node type to save, as an object.

Return value

Status flag indicating outcome of the operation.

6 calls to node_type_save()

File

core/modules/node/node.module, line 501
The core module that allows content to be submitted to the site.

Code

function node_type_save($info) {
  $existing_type = !empty($info->old_type) ? $info->old_type : $info->type;
  $is_existing = (bool) db_query_range('SELECT 1 FROM {node_type} WHERE type = :type', 0, 1, array(':type' => $existing_type))->fetchField();
  $type = node_type_set_defaults($info);

  $fields = array(
    'type' => (string) $type->type, 
    'name' => (string) $type->name, 
    'base' => (string) $type->base, 
    'has_title' => (int) $type->has_title, 
    'title_label' => (string) $type->title_label, 
    'description' => (string) $type->description, 
    'help' => (string) $type->help, 
    'custom' => (int) $type->custom, 
    'modified' => (int) $type->modified, 
    'locked' => (int) $type->locked, 
    'disabled' => (int) $type->disabled, 
    'module' => $type->module,
  );

  if ($is_existing) {
    db_update('node_type')
      ->fields($fields)
      ->condition('type', $existing_type)
      ->execute();

    if (!empty($type->old_type) && $type->old_type != $type->type) {
      field_attach_rename_bundle('node', $type->old_type, $type->type);
    }
    module_invoke_all('node_type_update', $type);
    $status = SAVED_UPDATED;
  }
  else {
    $fields['orig_type'] = (string) $type->orig_type;
    db_insert('node_type')
      ->fields($fields)
      ->execute();

    field_attach_create_bundle('node', $type->type);

    module_invoke_all('node_type_insert', $type);
    $status = SAVED_NEW;
  }

  // Clear the node type cache.
  node_type_cache_reset();

  return $status;
}
Login or register to post comments