tags:

views:

166

answers:

4

I have some code that creates a new node in Drupal, but I want to write some data to a Location field. How do I go about this? Is it possible to use the $node object?

+1  A: 

Is the location field a new field you want to add to your custom nodes?

You are going to have to handle a couple of hooks. insert, update, delete, load, form, view.

So you need to add the field to your table. Display the field in the form. Save it when inserting a new node. Update the node when editing the node. Load the field back into the node. Delete the row when the node is deleted. And display the field when node is viewed (teaser or full). node reference.

At the bottom of every one of those hook pages is an example using {mytable} and a field called 'extra'.

[edit] additional information.

The location module adds the fields $node->location and $node->locations. So I think to answer your question. Yes. You can modify them through the $node object.

Ed Haber
A: 

Sorry, shoul;d have explained better, it's a field created by the location module that I have added to the specific node type.

You should update your question with the info or use the comments to chat. Answers are not for general chat about the subject.
Ólafur Waage
A: 

$node->location->{field_name} if the node has one location, or $node->locations[{num}]->{field_name} should work.

Electric Monk
A: 

Cheers guys!