You are here

function entity_metadata_create_node in Entity API 7

Callback to create a new node.

1 string reference to 'entity_metadata_create_node'
_entity_info_add_metadata in ./entity.module
Adds metadata and callbacks for core entities to the entity info.

File

modules/callbacks.inc, line 917
Provides various callbacks for the whole core module integration.

Code

function entity_metadata_create_node($values = array()) {
  $node = (object) array(
    'type' => $values['type'],
    'language' => LANGUAGE_NONE,
    'is_new' => TRUE,
  );

  // Set some defaults.
  $node_options = variable_get('node_options_' . $node->type, array(
    'status',
    'promote',
  ));
  foreach (array(
    'status',
    'promote',
    'sticky',
  ) as $key) {
    $node->{$key} = (int) in_array($key, $node_options);
  }
  if (module_exists('comment') && !isset($node->comment)) {
    $node->comment = variable_get("comment_{$node->type}", COMMENT_NODE_OPEN);
  }

  // Apply the given values.
  foreach ($values as $key => $value) {
    $node->{$key} = $value;
  }
  return $node;
}