(Tutorial) Saving CCK and Taxonomy Fields with Flex and Drupal Services

Tutorial : Saving CCK and Taxonomy Fields with Flex and Drupal Services

The Services module of Drupal lets you easily access the backend data of your Drupal-based web site or application. Flex can connect to these services via AMFPHP and gives you the ability to quickly build a nice front-end to your application that calls remote methods to get at the application data.

This post is aimed at developers already familiar with how to save nodes with Flex and Drupal services. If you don’t know how, but are interested, check out the tutorials, screencasts, and examples in the Drupal Services Handbook.

One of the services available allows you to save a new node to the database. Saving a basic node is quite straightforward, but adding in other fields like taxonomy terms and Content Construction Kit (CCK) fields isn’t immediately obvious.

Saving CCK Text Fields

When you are building the node object that will be passed to node.save, you add a property in the format field_XX where XX is the name of your CCK field. Then the value of that property should be set to equal an array structure. Here is some sample Flex code using my CCK field “video”:

...
var nodeObject:Object = new Object();

nodeObject.type = "page";
nodeObject.name = username.text;
nodeObject.title = title.text;
nodeObject.body = body.text;
nodeObject.field_video = new Array({value:"http://www.youtube.com/"});
node.save(nodeObject);
...

Saving Taxonomy Terms

To save a list of taxonomy terms the process is similar. Build an array structure that will hold the taxonomy terms and then assign that array to the taxonomy property of the node object you are passing into node.save. Here is the sample Flex code:

| Read more..

Courtesy : Hybridhacking.com