I have a custom contact module that we periodically add new forms to - how can I get a list of all forms implemented by this module?
I'm integrating mollom and I want to just loop through all my forms in hook_mollom_form_list().
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityForms aren't implementations of anything as such, they're just plain PHP functions that happen to return a certain structure by convention. There's no registry of forms or anything like that, and the module that a form is defined in isn't tracked anywhere (it's not information that Drupal needs). Form functions don't even have to be named in any particular way.
There's also hook_forms()
which allows you to map multiple form IDs to a single form callback function, so that's an extra layer of complexity that would need to be handled somehow.
I can't think of a single reliable way you could get that information through code. Well, I'm sure you could use reflection to write something very specific to your module, provided your own form functions follow a predictable naming convention; but as far a generic solution goes, I'm 99.9% sure it isn't possible. Unless there's a creative way around that I'm just not thinking of.
If it's just for this single module, why not just write a function which returns an array of all the known form IDs. Then when you add a new form, update that function manually. It will be much easier than implementing the reflection code to do this.