I don't know whether this question is relevant for the group, but I asked it on StackExchange and it sank like a stone. Khalid said it would be okay to ask here, so I am doing so.
The long writeup is on StackExchange: http://drupal.stackexchange.com/questions/199743/alter-element-info-and-... . That has a bunch of details I am skimming over in this writeup.
The short version is that I am trying to allow negative prices in Ubercart. I believe I can do this by overriding the definition of the uc_price form element, and I am trying to figure out to do this without hacking the module directly.
I have been looking at hook_element_info_alter, but I do not understand when it is called and how to troubleshoot it. It appears that my test code is not being called at all.
My questions are:
-
Is this a correct approach to overriding the form behaviour in modules? If not what would be better?
-
How does hook_element_info_alter work? When is it called? How does Drupal know to alter Ubercart types when I alter them in my custom module?
-
How do I troubleshoot this process? (There is a comment on the StackExchange question that suggested watchdog(), which I think is helpful but which has given me no results yet.)
I am happy if you reply here or the StackExchange question. If I figure out this problem then I will probably update the answer, because there does not seem to be much documentation on this topic (that I can find, anyways).
Comments
A few pointers ...
Not that I tried this myself, but the internets say that you need to alter the cart item not the product.
This seems specific to your use case:
http://drupal.stackexchange.com/questions/160197/change-product-price-be...
This says it can be done with another function:
http://drupal.stackexchange.com/questions/57608/ubercart-alter-product-p...
Post back (here and in stackexchange), whether it works or not.
Drupal performance tuning, development, customization and consulting: 2bits.com, Inc..
Personal blog: Baheyeldin.com.
The above solutions solve a
The above solutions solve a slightly different problem: they programmatically alter prices in Ubercart. I want the user to be able to alter the price, but I wanted to disable the check for negative values.
It turns out that I was on the right track on my stackexchange question: hook_element_info_alter was the way to go. As usual, the problem was stupid: I was not clearing cache fully after making changes to the function. It appears that the function is called much earlier than when you see a form, and the results are cached for a long time.