5

So I'm able to create a page programmatically, BUT even though I'm specifying the 'full_html' filter, the page is being created with the 'filtered_html' filter which means that the code I'm writing to the page after it's created is being stripped out. Here's the line I'm using to set the filter type:

$node->body[$node->language][0]['format'] = 'full_html';

Why is the filter type being ignored when the node is created?

Thanks in advance, Bryan

3

OK, as it turns out, the 'body' field is not called 'body' in our Drupal installations; it's called 'field_page_body'. Changing that in the code made everything work.

0

It could very well be due to the default weight of the filter. You set this in content authoring > input formats

just make "full html" the first option. let me know if that works as I had a similar issue before.

  • That worked-- of course, now if I want to create nodes with other filter types, they won't work. Not sure if this is a bug, or if I'm doing something horribly wrong (although the code above is how it's done in numerous tutorials I've read). Thanks for the workaround-- it may do the trick for me for the time being. – Bryan Green Jan 16 '13 at 22:19
  • OK, as it turns out, the 'body' field is not called 'body' in our Drupal installations; it's called 'field_page_body'. Changing that in the code made everything work. – Bryan Green Jan 17 '13 at 0:39
0

I'm using

node_save($node); 
$wrapper = entity_metadata_wrapper('node', $node->nid); 
$wrapper->body->set(array('value' => body_text, 'format'=>'full_html'));

hope it's helpful.

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.