I'm trying to execute an extra submit function after autoadmin_edit_form_submit. I need to because I have to do some specific processing after having inserted a new record. It has to be after autoadmin_edit_form_submit because I need the ID of the new record.
The unconditional drupal_goto at the end of autoadmin_edit_form_submit is preventing other submit methods to be executed after autoadmin_edit_form_submit.
The attached patch creates a new schema attribute skip_edit_redirect which has a default value of FALSE. Setting this attribute to TRUE allows the user of Auto Admin to have it's own submit methods called after autoadmin_edit_form_submit. Obviously if the user sets this value to TRUE, it's his/her responsability to redirect to a proper page after inserting/editing a record.
For extension I created a similar option for delete submit named skip_delete_redirect.
I believe existing code won't be affected by this new feature, i.e., present behaviour will be unchanged. Auto Admin will behave differently only if the user has one of the new attributes set to TRUE. Not having the attribute set at all (all existing code) or having it as FALSE will preserve current behaviour.
Please consider including this patch in Auto Admin code.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | autoadmin.skip_redirect_3.patch | 3.31 KB | rsevero |
| #1 | autoadmin.skip_redirect_2.patch | 3.31 KB | rsevero |
| autoadmin.skip_redirect.patch | 2.76 KB | rsevero |
Comments
Comment #1
rsevero commentedPlease disregard the previous patch as after some reviewing of Form API documentation I have a new and much improved patch.
This new patch fixes the unconditional redirect at the end of
autoadmin_edit_form_submitsimply by substituting thedrupal_gotoat the end ofautoadmin_edit_form_submitwith a setting of$form_state['redirect']as per instructions on item 4 at the end of the "Submitting forms" section of http://drupal.org/node/751826.It also presents messages on record insertion and updating as per suggestion on the same above item of http://drupal.org/node/751826.
Besides that it includes the id of the newly created record (on insertion) as per instructions on http://drupal.org/node/144132#redirect.
Please consider this patch for Auto Admin.
Comment #2
rsevero commentedFixing typo on previous patch.
Comment #3
_rune commentedHi
Thats a great patch, when coding these parts I had some bugs with $form_state['redirect'] and opted to use drupal_goto() instead as a quick fix. Don't know if its fixed by using a newer drupal version now or that I had some other error at the time, but great thx! I'm in the process of refactoring your patch a bit. Moving it to two functions in autoadmin.db.inc called autoadmin_db_insert_record($schema, $data) and autoadmin_db_update_record($schema, $data) and have a single question. What is the meaning of
?
Also very nice with the status messages, think I will change them a bit so they use the schema titles instead of the table names. Will commit it to head and you can tell me what you think.
Cheers
Rune
Comment #4
rsevero commentedGlad you liked it.
The code above passes the new record ID in $form_state so other submit handlers can have easy access to the ID of the newly inserted record. It's really useful.
Comment #5
_rune commentedNeeds tests and cleanups.
Comment #6
rsevero commentedCould you detail which cleanups you believe are necessary?
Comment #7
_rune commented1) The text's should read something like:
[SCHEMA_TITLE] with id %new_record_id was changed/inserted/deleted.
Similar with error messages.
2) The function is too long and not DRY.
3) Simpletests to test new behaviour should be written.
Cheers
Rune
Comment #8
jonhattana call to watchdog() may also be of interest, also including the user that did the operation.
Comment #9
_rune commentedHi rsevero
Your patch is finally in cvs, sorry it took so long time. You care to review? http://drupal.org/project/cvs/581522.
Comment #10
_rune commentedFixed in v. 1.5.