1

Dale McGladdery: Creating and Updating Nodes Programmatically in Drupal 7

http://www.group42.ca

The steps for programmatically creating a node are:

  • Create a PHP object representing the node data
  • Save the object using the node_save() function

While the mechanics are simple, there is an important responsibility involved. The Drupal work flow does data validation before calling the node_save() function; node_save() does no validation. By calling node_save() directly your code takes the responsibility for providing valid data.

Drupal 7 Changes

A quick note for those of you familiar with Drupal 6. You'll notice two changes in Drupal 7:

Body Field Is No Longer Special

In Drupal 6 the body field was special. Specifically, it had a different data structure than other fields and it always existed, even if it wasn't used. With Drupal 7 the body field is a standard field provided by core and is truly optional.

Language

Language specification is required for the node and some fields.

Basic Node Creation

The following code assumes an unchanged Drupal 7 Standard installation and will create a Drupal 7 article node.
read more

Read »
admin's picture
Created by admin 1 year 37 weeks ago – Made popular 1 year 37 weeks ago
Category: Open Source CMS   Tags:
  • admin's picture
    admin

Your Ad Here
Domain Sale! $7.99 .com at GoDaddy

User login

Who's online

There are currently 0 users and 5 guests online.