0

In Drupal 7, i need to Programmatically create the Nodes. As usual, there are Different Fields set for Different Content Types.

For very simple example:

Content Type: "car"
Fields: "Model", "Engine", "GearType"

Content Type: "article"
Fields: "Title", "Author", "Media"

What i want to be confirmed here is, while i am creating a new node, for e.g by using:

$node = new stdClass();
$node->type = "car";

Then..

  • Is that (currently creating) new $node has been initiated/loaded with its related/corresponded fields, already before get saved?
  • To be more clear, if i just suddenly Save a node node_save($node) (without filling any other related fields) will that node be still having (following) its proper Content Type structure?
4

1 回答 1

1

我认为这就是您要寻找的东西:

$node = new stdClass();
$node->type = 'article';
node_object_prepare($node);

这里有一篇很好的博客文章:http: //www.group42.ca/creating_and_updating_nodes_programmatically_in_drupal_7

于 2012-10-11T16:41:05.077 回答