You are here

function defaultcontent_set_default in Default Content 7

Same name and namespace in other branches
  1. 7.2 defaultcontent.module \defaultcontent_set_default()

Used to set a default

Parameters

$name: The machine name

$nid: The nid of the node

3 calls to defaultcontent_set_default()
defaultcontent_node_delete in ./defaultcontent.module
Implements of hook_node_delete().
defaultcontent_node_insert in ./defaultcontent.module
Implements hook_node_insert().
defaultcontent_remove_default_content in ./defaultcontent.module

File

./defaultcontent.module, line 197
Module file for the Default content module which allow export and import of default content in a Drupal site.

Code

function defaultcontent_set_default($name, $nid = NULL) {
  $current_nid = defaultcontent_get_default($name);
  if ($nid === FALSE) {
    db_delete('defaultcontent')
      ->condition('name', $name)
      ->execute();
  }
  if ($current_nid === $nid) {

    // nothing to change here
    return;
  }
  $record = (object) array(
    'name' => $name,
    'nid' => $nid,
  );
  $primary_keys = $current_nid === FALSE ? array() : array(
    'name',
  );
  drupal_write_record('defaultcontent', $record, $primary_keys);
}