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)


quicksketch’s picture

Status:Active» Needs review

Nice, 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'.

jwineinger’s picture

new600 bytes

Updated patch with quicksketch's feedback

quicksketch’s picture

Status:Needs review» Fixed

Sweet, works for me. Committed to 3.x branches.

Status:Fixed» Closed (fixed)
Issue tags:-options, -webform, -select, -dynamic, -pre-built, -hook_webform_select_options_info

Automatically closed -- issue fixed for 2 weeks with no activity.