This is great Peter, thanks!
I have created a module called Webform options based on this code, but I was wondering: would it be possible to display the views in alphabetical order instead of ordered by id? Although it works great, this would be just a little bit more user friendly as a general solution.

In /sites/all/modules create a folder called webform_options with these two files:

webform_options.info
;$Id$
name = Webform options
description = Enables all views as webform options
package= Webform
core = 7.x

files[] = webform_options.module
version = "7.x-1.0"
core = "7.x"
project = "Webform options"

; Module dependencies
dependencies[] = webform

webform_options.module

function webform_options_webform_select_options_info() {
$items = array();

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' => '_webform_options_get_view_options',
'options arguments' => $viewName,
);
}
}
}

return $items;
}

function _webform_options_get_view_options() {
$args = func_get_args();
$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;
}

function webform_options_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'webform_options'),
//'path' => drupal_get_path('module', 'webform_options') . '/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.