Permalink

Sorry, this is the correct code. I had some stuff hardcoded and a faulty (and ugly) database call. I now use the views_get_all_views() function provided by Views itself.

  /
   * 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 = views_get_all_views();
                foreach($viewNames as $viewName) {
                 if($viewName->disabled==0) {
                    $viewName = $viewName->name;
                    $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.