Closed (fixed)
Project:
Ubercart
Version:
6.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
16 Jul 2009 at 16:35 UTC
Updated:
7 Feb 2011 at 21:15 UTC
Jump to comment: Most recent file
Present implementation doesn't allow contrib modules to use hook_form_alter() et al to manipulate attributes without modifying module weights. Lyle and I have discussed the issue and we both feel it's necessary to add an Ubercart layer form alter hook so that contrib/other modules can easily use the drupal layer form alter hook. The reason, we decided, was because Ubercart, being a system on a system, needs to avoid limiting the Drupal layer programmability so developers can be familiar with the platform in less time. Another benefit is that low-level changes (read as evil :p), such as changing module weights, are not necessary.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 521378_200907231338-0400.patch | 7.93 KB | sammys |
| #8 | 521378_cart_form_alter.patch | 4.67 KB | Island Usurper |
| #2 | 521378_cart_form_alter.patch | 3.33 KB | Island Usurper |
Comments
Comment #1
sammys commentedAnother note: the change won't break current contrib though we recommend contrib maintainers think carefully about moving things into the Ubercart layer hook so module authors can modify the form elements they are adding to the form.
Comment #2
Island Usurper commentedI had to do a little bit of rearranging in uc_attribute_form_alter() to change it into uc_attribute_add_to_cart_form_alter() because a lot of the default data put on forms isn't available yet. I think that's the right spot for the drupal_alter(). There aren't many other good places.
Comment #3
sammys commentedPatch appears to work ok for the stuff I need to do. Attributes are showing in the cart, order review and invoice. Attributes appear to be missing from the user's order view though the invoice shows it.
Comment #4
sammys commentedOk... this was because I had a dirty branch. RTBC!
Comment #5
Island Usurper commentedAlright. Committed, and updated the documentation about changes from 1.x to 2.x.
Comment #6
Island Usurper commentedActually, we still need to document hook_add_to_cart_form_alter() in hooks.php.
Also, should we make the $form_state get passed by reference, the way hook_form_alter() does?
Comment #7
sammys commentedYeah I agree that adding $form_state is a positive step. The same thing needs to happen across the board actually, but we can make baby steps. :)
A related patch for $form_state stuff: #435084: Using $form_state instead of $_POST in cart forms
That one is needed to support injection of content_profile (hence CCK) forms into the user information part of checkout.
Comment #8
Island Usurper commentedActually, I had just noticed that the hook functions expected $form_state to be passed by reference, so we need to use the '__drupal_alter_by_ref' key anyway.
Comment #9
sammys commentedCan we move the following two lines into an API function? Preferably one that takes the alter "name" (in this case 'add_to_cart_form') and then all remaining args get pushed along to drupal_alter() using call_user_func_array() or something?
Comment #10
sammys commentedLyle and I have discussed the namespace clash with what the Drupal layer does and have decided to do the following:
E.g uc_attributes will now have a uc_attributes_uc_form_alter() hook.
I'm in the middle of updating the patch.
Comment #11
sammys commentedPatch attached.
Comment #12
Island Usurper commentedWorks splendidly.
I guess we'll just have to figure out which forms will have alterations that need to be altered on a case-by-case basis.
Committed.
Comment #13
sammys commentedJolly good sir. Another one knocked off its perch.
Comment #14
vitis commentedlooking forward to trying the patch
is it already fixed in one of the devs?
Comment #15
Island Usurper commentedYes, it is.
Comment #16
tejaspmehta commentedhello,
do you have any idea that how form_alter will work for checkout process ? i want to store order_id in another table once order is generated. for that i am using following code but it is not working well for me
Now only help i need in this code is when anyone press submit button say Review Order and confirm order at that time i want to execute modulename_getorderid function. $form['#submit'][] might be the way but its not working so if anyone have idea than please post your reply.
Comment #18
summit commentedSubscribing, needing also uc_form_alter for payment redirecting.
Greetings,
Martijn
Comment #19
torgospizzaMartijn,
This issue is CLOSED so why are you subscribing? If there is a feature you need not found in this patch, you need to open a new issue.
Comment #20
summit commentedOk, sorry it was late, I wanted to bookmark, not subscribe, sorry to bother you. greetings, Martijn