I don't want to mess around in the code if I want to add a list so I made the code pull the lists automatically from the Views database. The complete code now reads (my module is called dynaoptions);
/**
* Provide a select options component to Webform. The values are
* populated via a call to _dynaoptions_get_options, which returns
* an array of nodes.
*
* @return void
* @author Kosta Harlan
*/
function dynaoptions_webform_select_options_info() {
$items = array();
/**
* Returns an array of Story nodes keyed on the node ID.
*
* @return array
* @author Kosta Harlan
*/
function _dynaoptions_get_story_nodes() {
$nodes = array();
$select = db_query(db_rewrite_sql("SELECT nid, title FROM
{node} WHERE type = 'story' ORDER BY title"));
while ($node = db_fetch_object($select)) {
$nodes[$node->nid] = $node->title;
}
return $nodes;
}
/**
* Options callback for webform_select_options_info().
* The assumption is that your view is displaying node data.
*
* @return array of items to populate the select list with.
* @author Kosta Harlan
*/
function _dynaoptions_get_view_options() {
$args = func_get_args();
// Change 'my_sample_view' to the machine name of your View.
$view = views_get_view($args[3], true);
$view->execute();
$items = array();
I made an addition to the code.
I don't want to mess around in the code if I want to add a list so I made the code pull the lists automatically from the Views database. The complete code now reads (my module is called dynaoptions);
/**
* Provide a select options component to Webform. The values are
* populated via a call to _dynaoptions_get_options, which returns
* an array of nodes.
*
* @return void
* @author Kosta Harlan
*/
function dynaoptions_webform_select_options_info() {
$items = array();
}
/**
* Returns an array of Story nodes keyed on the node ID.
*
* @return array
* @author Kosta Harlan
*/
function _dynaoptions_get_story_nodes() {
$nodes = array();
}
/**
* Options callback for webform_select_options_info().
* The assumption is that your view is displaying node data.
*
* @return array of items to populate the select list with.
* @author Kosta Harlan
*/
function _dynaoptions_get_view_options() {
$args = func_get_args();
// Change 'my_sample_view' to the machine name of your View.
$view = views_get_view($args[3], true);
$view->execute();
$items = array();
}
/**
* Implementation of hook_views_api().
*/
function dynaoptions_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'dynaoptions'),
//'path' => drupal_get_path('module', 'dynaoptions') . '/includes',
);
}