I recently had need to dynamically create "Pre-Built Option Lists" using hook_webform_select_options_info(). I am integrating Salesforce with the sf_webform module and I wanted to use the picklist values defined in a Salesforce field as the options for a webform select component. Since all of the Salesforce picklist fields have similar array structures in PHP, there is only a single callback function to generate the different option lists -- each call just needs to have different data to work with. However, the callback functionality for select options does not support callback arguments, so there was no straightforward way to get to the data needed in the callback.
I've attached a simple patch which allows you to specify "callback arguments" when defining the option lists in hook_webform_select_options_info().
Sample usage:
function hook_webform_select_options_info() {
$items = array();
$items['days'] = array(
'title' => t('Days of the week'),
'options callback' => 'webform_options_days',
'callback arguments' => array("show_weekends" => FALSE),
);
return $items;
}
function webform_options_days($component, $flat, $filter, $custom_args) {
// $custom_args is array("show_weekends" => FALSE)
}
Comment | File | Size | Author |
---|---|---|---|
#2 | webform_callback_options_args.patch | 600 bytes | jwineinger |
webform_callback_args.patch | 653 bytes | jwineinger | |
Comments
Comment #1
quicksketchNice, I could see how this would be helpful. I've been trying to figure out how to pass user-configurable arguments to the options callback, but it would require a lot of additional work on the select component form (AJAX requests after every change essentially). This seems like it would be related to that functionality somehow, but in a non-configurable way.
The only thing I'd probably change is that I think calling the property 'options arguments' (sounds funny I know) may be better than 'callback arguments' in case we end up with multiple callbacks. Similar to how the menu system uses 'page callback' and 'page arguments' to separate them from 'access callback' and 'access arguments'.
Comment #2
jwineinger CreditAttribution: jwineinger commentedUpdated patch with quicksketch's feedback
Comment #3
quicksketchSweet, works for me. Committed to 3.x branches.