![]() |
|||||||
Hybrid Hacking provides tutorials on how to integrate with some of today's hottest web services.
|
Saving CCK and Taxonomy Fields with Flex and Drupal Services
Thu, 08/30/2007 - 16:49
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: ... var taxonomyArray:Array = new Array(); // set the 'technology' vocabulary to have the terms with id 1 and 2 taxonomyArray['technology'] = new Array(1,2); // set the 'industry' vocabulary to have the terms with id 3 and 4 taxonomyArray['industry'] = new Array(3,4); nodeObject.taxonomy = taxonomyArray; node.save(nodeObject); ... Comments
Thu, 10/04/2007 - 01:58 — RobRoy (not verified)
Typo: "nodeObject.taxonomy = node.save(nodeObject);"
Thu, 10/04/2007 - 03:18 — shongrunden
Thanks RobRoy I fixed that typo.
Mon, 11/26/2007 - 07:36 — raydale (not verified)
Thanks this has been a good help to me. However, I am now stumped with the CCK Image Field. Although I can upload an image to the server, I cannot populate the image field itself. Any ideas?
Mon, 10/20/2008 - 14:14 — Ben Reed (not verified)
Hi! A little late I know but any help would be appreciated. I have recently been playing with Drupal and Flex as a combination and have hit a stumbling block with CCK. I figured much of the above before finding this blog post but every time I try to save a CCK node I get the error: "array_merge(): Argument 1 is not an array". Do you have any ideas as to what may be causing this?
Fri, 10/31/2008 - 03:14 — Hal (not verified)
Well this looks great but it's not working for me. But one thing struck me as odd, you define taxonomyArray as an array, but then you treat it like an Object taxonomyArray['technology']
Sun, 11/02/2008 - 22:12 — Chris (not verified)
Thanks so much for sharing - I have been killing myself trying to figure this out Post new comment |
||||||