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 Purencool on
Hi all,
I have been playing with creating nodes programmatically. In the content type Basic Page I have added a field basic_image. How do I tell the node where the image is and to upload it when I install my custom module? The example below is the node inside my custom module .install file.
//-- About page
$node = new stdClass();
$node->type = 'page';
node_object_prepare($node);
$node->title = 'About';
$node->language = LANGUAGE_NONE;
$node->menu['enabled'] = 1; // 1 to enable providing a link in main menu
$node->menu['link_title'] = 'About';
$node->menu['description'] = 'What is this website about page';
$node->menu['parent'] = 'main-menu:0';
$node->menu['weight'] = 5;
$node->body[$node->language][0]['value'] = testArticle();
$node->body[$node->language][0]['format'] = 'full_html';
$node->changed = $_SERVER['REQUEST_TIME']; //yet to be tested
$node->created = $_SERVER['REQUEST_TIME']; //yet to be tested
$node->status = 1; // 1 means published
$node->promote = 0;
$node->revision = 0;
$node->path['alias'] = 'about';
node_submit($node);
node_save($node);
Comments
Reference
This might help you out , https://www.drupal.org/node/201594
Worked great thanks
Worked great thanks
https://www.purencool.digital