node_submit

5 node.module node_submit($node)
6 node.module node_submit($node)
7 node.module node_submit($node)
8 node.module node_submit($node)

Prepare node for save and allow modules to make changes.

3 calls to node_submit()

File

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

Code

function node_submit($node) {
  global $user;

  // Convert the node to an object, if necessary.
  $node = (object) $node;

  // Auto-generate the teaser, but only if it hasn't been set (e.g. by a
  // module-provided 'teaser' form item).
  if (!isset($node->teaser)) {
    $node->teaser = isset($node->body) ? node_teaser($node->body, isset($node->format) ? $node->format : NULL) : '';
  }

  $access = user_access('administer nodes');
  if ($access) {
    // Populate the "authored by" field.
    if ($account = user_load(array('name' => $node->name))) {
      $node->uid = $account->uid;
    }
    else {
      $node->uid = 0;
    }

    $node->created = $node->date ? strtotime($node->date) : NULL;
  }
  // Force defaults in case people modify the form:
  $node_options = variable_get('node_options_' . $node->type, array('status', 'promote'));
  foreach (array('status', 'moderate', 'promote', 'sticky', 'revision') as $key) {
    if (!$access || !isset($node->$key)) {
      $node->$key = in_array($key, $node_options);
    }
  }

  // Do node-type-specific validation checks.
  node_invoke($node, 'submit');
  node_invoke_nodeapi($node, 'submit');

  $node->validated = TRUE;

  return $node;
}
Login or register to post comments