Advertisement
Guest User

Drupal 7 – Dynamic select options for Webform

a guest
Jul 31st, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1. <?php
  2. function webform_options_webform_select_options_info() {
  3.    
  4.     // get all content types
  5.     $node_types = array_keys(node_type_get_names());
  6.    
  7.     $items = array();
  8.     // for each of the content types, create an item
  9.     foreach($node_types as $ntype){
  10.         // returns function names as lambda_1, lambda_2, ...
  11.         $callback_func = create_function('', 'return _get_node_titles("'.$ntype.'");');
  12.         $items[$ntype] = array(
  13.             'title' => t('Node: ' . $ntype),
  14.             'options callback' => $callback_func,
  15.         );
  16.     } // foreach
  17.     return $items;
  18.  
  19. } // webform_options_webform_select_options_info()
  20.  
  21. function _get_node_titles($node_type) {
  22.  
  23.     $options = array();
  24.     $sql = "SELECT nid, title FROM {node} WHERE type = '$node_type'";
  25.     $result = db_query($sql);
  26.     foreach ($result as $row) {
  27.         $options[$row->nid] = $row->title;
  28.     }
  29.     return $options;
  30. } // _get_node_titles()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement