[development] tricky drupal_execute() / hook_form_alter() question

Emma Irwin emma.irwin at gmail.com
Sat Jul 30 00:57:07 UTC 2011

I've used node_save without having to worry about defaults for irrelevant fields. Worked fine for CCK for me
Personally, I think that your alternate solution & function goes too far into a zone of complexity that you'll have more bugs as a result. I would also feel for any developer that comes after you and has to maintain that code :/

Sent from my iPhone

On Jul 29, 2011, at 12:21 PM, "David Cohen" <drupal at dave-cohen.com> wrote:

> I'm trying import some data from a user's Facebook profile into Drupal. 
> The site in question has a lot of moving parts: Content Profile, CCK,
> Drupal for Facebook.
> I'd like to query facebook for info about the user, then create or
> update a node with the data.  The node contains a lot of fields, and I'm
> only interested in updating 1 or 2 (or 3 or 4) of them.
> My preference is to use drupal_execute() to create/update the profile
> node.  To do this, I have to fill out a $form_state['values'] array. 
> I've tested this and noticed that if I leave out the values for any
> field in the node, that field will be reset to blank.  In other words my
> code needs to fill out values for all fields.  But to do so essentially
> prevents anyone from adding more fields via CCK.  The code would need to
> be updated for every change to the content type, which is too onerous.
> There are posts on drupal.org describing this same problem, and
> suggesting using node_save() instead of drupal_execute() for this
> purpose.  What do the experts on this list recommend, drupal_execute()
> or node_save()?
> I had the thought that during hook_form_alter(), I could scan the form
> for all #default_values, and use them to populate the
> $form_state['values'].  A function able to do that would, it seems to
> me, make drupal_execute() much easier to use.  That code would have to
> navigate the entire $form tree (at least all element children).  And
> would have to be smart about where #tree is true in order to get all the
> #default_values into the right $form_state['values'].  Has anyone
> attempted such a thing?
> Thanks in advance, -Dave

More information about the development mailing list