[development] Curl-based content generation

Gerhard Killesreiter gerhard at killesreiter.de
Thu Feb 5 21:31:41 UTC 2009

Hash: SHA1

Earl Dunovant schrieb:
> On Thu, Feb 5, 2009 at 3:37 PM, M. Fioretti <mfioretti at nexaima.net> wrote:
>> On Thu, Feb 05, 2009 13:50:46 PM -0500, Earl Dunovant wrote:
>>> Use drupal_execute().
>>> http://api.drupal.org/api/function/drupal_execute/6
>> The only problem is that to write such a script one needs to know in
>> advance:
>> - the exact sequence of URLs to call (isn't this documented anywhere
>>  but in the source code itself?)
>> - a list of the names and admissible values of all the form variables
>>  to pass to curl when it calls each one of those URLs. (**)
>> You need to know the fields in the form to create the node type you want to
> create. You put the data in $form_state['values'], just as is passed into,
> hook_form_alter(). You can get that by writing a hook_form_alter() function
> that calls var_export($form_state['values'], 1);
> Then,
> 1: call drupal_get+form() to get the from-defining array
> 2: populate your $form_state['values'} array with your new node data
> 3: call drupal_execute($form_id, $form, $form_state);
> Lather, rinse, repeat until you're done. No URLs involved. Stick it in a
> module and call it from your script or a menu as you prefer.
> Read the docs and you'll see how it's done.

While I agree that this is the right approach, it also has some
problems. The most important one is that access permissions for the
forms aren't checked. You can get around that by checking yourself in
hook_form_alter (you also need to unset #programmed in case you want to
deny access for some reason). I've not gotten field level cck
permissions to work. Also be careful to set #redirect to false in case
you want to get useful feedback (e.g. from the services module).

Version: GnuPG v1.4.9 (GNU/Linux)


More information about the development mailing list