[development] tricky drupal_execute() / hook_form_alter() question
drupal at dave-cohen.com
Fri Jul 29 19:21:20 UTC 2011
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()
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