Permalink

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();

    if (function_exists('_dynaoptions_get_story_nodes')) {
            $items['story-nodes'] = array(
        'title' => t('Story nodes'),
        'options callback' => '_dynaoptions_get_story_nodes',
      );
    }

    if (module_exists('views')) {
            $viewNames = array("Countries","Councils");
            $result = db_query_range("SELECT name FROM views_view");
            while($viewName = db_fetch_array($result)) {
                $viewNames = $viewName['name'];
            }
            foreach($viewNames as $viewName) {
                $items[$viewName] = array(
                        'title' => $viewName,
                        'options callback' => '_dynaoptions_get_view_options',
                        'options arguments' => $viewName,
                );
            }
    }

return $items;

}

/**
* 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();

foreach ($view->result as $item) {
  $full_node = node_load($item->nid);
  $items[$item->nid] = $full_node->title;
}
return $items;

}

/**
* 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',
);
}

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.