1

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?
2

The node can have fields attached to it. If any are required and not provided then I believe your save() will fail with an error message. If your fields provide a default value that value will be used for those fields.

If there are no required fields. The basic node information (nid, type, title?) will be the only values set on your new node (and timestamps, owner uid).

I believe it's up to you the developer to assure the fields have the data you want when you save the node (and meet the Requirements of the node/fields configuration) from the Field UI.

1
  • Oh, so now i realize that, i only need to consider about the Required Fields which will be the only problems. :) Oct 11 '12 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.