Hello.

Does anybody know how to programmatically set the input format when creating Drupal nodes?
Is there an attribute to the node object representing the input format?

Thanks.
Pol

Comments

JJacobsson’s picture

Yes. It's practically magic, but just set 'format' in the node to the option in the input filter field. At least that's what it seems like...

I do:

$node->format = 3; 

and that results in the input format of the body field to be "Full HTML" when I open the resulting node for edit. I haven't tried it but I assume setting format = 2 will result in "PHP code" being selected instead.

I got this from: http://drupal.org/node/67887

Scroll down a bit and there's a fairly comprehensive script that creates nodes from content in CSV files.

palabat’s picture

Thanks.
Just what I need.