Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By GibsonSG76 on
Hi,
I installed Open Atrium and I tried to create a node with the node_save function.
<?php
$node = new stdClass(); // We create a new node object
$node->type = "page"; // Or any other content type you want
node_object_prepare($node); // Set some default values.
$node->title = "Your title goes jere";
$node->language = LANGUAGE_NONE; // Or any language code if Locale module is enabled. More on this below *
$node->path = array('alias' => 'content/Pedro2'); // Setting a node path
$node->uid = 1; // Or any id you wish
$node->body[$node->language][0]['value'] = 'This is a body text';
$node->body[$node->language][0]['summary'] = 'Here goes a summary';
$node->body[$node->language][0]['format'] = 'filtered_html';
$node = node_submit($node);
node_save($node);
?>
When I execute this script from my module, it's works. On my database I have a new node but when I try to see it it's not works anymore.
My node appears on my content list (/admin/content). When I click on it, I'm redirected to the node. On this page I see the node's title, the author's name, the date but not the body. The node's content not appears.
Why ?
I tried to execute this script on a Drupal 7 but it's not works too.
Best regards
Comments
EDIT
When I click on "EDIT" to edit the node, on the new page the textarea contains the value of "body".
And when I click on "save" to udpate the node, it's works ! After update, when I display the node I see the title, the date, the author AND the body ! But when I only create a node, the body is not displayed ...
_
iirc, you need to set the text format of the body field when you create it.
Already done
Thanks for your answer:
I've already set the text format with 'filtered_html'. I tried with "WISIWYG" and "HTML" and it's not works too.
Fixed !
I found out what was wrong.
The problem was I didn't use the right value for text format.
I didn't use the "machine name", so you need to set the text format with the following value.
For wysiwyg => panopoly_wysiwyg_text
For HTML => panopoly_html_text
For FULL HTML => full_html
For Plain text => plain_text
_
Excellent! Thanks for posting back your working solution-- I'm sure it will help others.