Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
/**
* Implements hook_form_FORM_ID_alter().
*/
function mymodule_form_honeypot_admin_form_alter(&$form, &$form_state, $form_id) {
$form['enabled_forms']['mymodule'] = array('#markup' => '<h5>' . t('Mymodule Forms') . '</h5>');
$form['enabled_forms']['honeypot_form_mymodule_special_form'] = array(
'#type' => 'checkbox',
'#title' => t('Mymodule special form'),
'#default_value' => variable_get('honeypot_form_mymodule_special_form', 0),
);
}
This is what I did ^, and it works great. The question is, will it work in the future? I think it would be better to register custom forms with a new hook, something like:
/**
* Implements hook_honeypot_register_custom_forms();
*/
function mymodule_honeypot_register_custom_forms() {
$forms = array(
'mymodule_registration_form' => array(
'title' => t('Mymodule registration form'),
'category' => t('Mymodule Forms'),
),
'mymodule_contact_form' => array(
'title' => t('Mymodule contact form'),
'category' => t('Mymodule Forms'),
),
);
return $forms;
}
Comments
Comment #1
geerlingguy CreditAttribution: geerlingguy commentedYour current solution should work great for the foreseeable future, as that form won't be changed unless there's a new major version. Having a hook for adding forms to the defaults on the settings array is a good idea, but I'll have to think about how I'd want that to work before committing to anything.
If I had a good API for this, I could make a secondary module like honeypot_extra_forms that adds in webforms, comment forms, etc. That would keep the main Honeypot module a bit cleaner as well.
Comment #2
geerlingguy CreditAttribution: geerlingguy commentedSee also: #2030545: Add a honeypot setting to the node/edit page?.
Comment #3
geerlingguy CreditAttribution: geerlingguy commentedI think, for now, I'm going to close this issue and put support behind #2342473: Allow for more flexible form configuration, which would allow any form to be added simply by pasting in the form ID. That method is a lot more flexible in general, and wouldn't rely on extra 3rd party module support (or a separate 'Honeypot Extras' module or something like that).