I'm working on a drupal 7 module, and I've got a 'help' document that I want to programmatically include when the module is loaded. The 'help text' in question has some html included, and I would like to preserve it. In drupal 6 I did something like this:
$newnode = array (
'title' => 'help page',
'uid' => 1,
'type' => 'page',
'status' => 1,
'promote' => 1,
'format' => 2,
'body' => $helptext, // contents for help node with html
);
node_save($newnode);
In drupal 7 I can get the contents of the 'help text' saved as a node, BUT the html is not all preserved. I thought setting 'format' to 2 would fix this problem, but it doesn't. My code now looks something like that below. How do I get full html for my help text?
$newnode = array (
'title' => array ( FIELD_LANGUAGE_NONE => array(array('value' => "Help Page"))),
'uid' => 1,
'type' => 'page',
'status' => 1,
'promote' => 1,
'format' => 2,
'body' => array(FIELD_LANGUAGE_NONE => array(array())),
);
$body = array(
'value' => $helptext,
'input_format' => null,
);
$newnode['body'][FIELD_LANGUAGE_NONE][0] += $body;
$node = (object) $newnode;
node_save($node);
Thanks for your time. I hope I haven't forgotten anything. Any help would be appreciated.
Comments
I think I figured it out on
I think I figured it out on my own. This is the new version:
$newnode = array (
'title' => array ( FIELD_LANGUAGE_NONE => array(array('value' => "Help Page"))),
'uid' => 1,
'type' => 'page',
'status' => 1,
'promote' => 1,
'format' => 2,
'body' => array(FIELD_LANGUAGE_NONE => array(array())),
);
$body = array(
'value' => $helptext,
'input_format' => null,
'format' => 2, // << this is the new code!
);
$newnode['body'][FIELD_LANGUAGE_NONE][0] += $body;
$node = (object) $newnode;
node_save($node);