You are here

webform_term_opts.module in Webform Term Options 6

Same filename and directory in other branches
  1. 7.4 webform_term_opts.module
  2. 7 webform_term_opts.module

This is a simple module implementing a webform hook to offer vocabulary terms to be used as options in form components.

@author Martin Martinov <martinm@propeople.dk>

File

webform_term_opts.module
View source
<?php

/**
 * @file
 * This is a simple module implementing a webform hook to offer vocabulary
 * terms to be used as options in form components.
 * 
 * @author Martin Martinov <martinm@propeople.dk>
 */

/**
 * Implementation of hook_webform_select_options_info().
 */
function webform_term_opts_webform_select_options_info() {
  $items = array();
  $vocabularies = taxonomy_get_vocabularies();
  foreach ($vocabularies as $voc) {

    /**
     * @todo Add a setting that enables each vocabulary to be shown here.
     */
    $items['vid_' . $voc->vid] = array(
      'title' => $voc->name,
      'options callback' => 'webform_term_options_vocabulary_terms',
      'options arguments' => $voc->vid,
    );
  }
  return $items;
}

/**
 * Option list containing all terms of specified vocabulary.
 */
function webform_term_options_vocabulary_terms($component, $flat, $filter, $vid) {
  $terms = array();
  $tree = taxonomy_get_tree($vid);
  if ($flat) {
    foreach ($tree as $term) {
      $terms['tid_' . $term->tid] = $term->name;
    }
  }
  else {
    foreach ($tree as $term) {
      $terms['tid_' . $term->tid] = str_repeat('-', $term->depth) . $term->name;
    }
  }
  return $terms;
}

Functions

Namesort descending Description
webform_term_options_vocabulary_terms Option list containing all terms of specified vocabulary.
webform_term_opts_webform_select_options_info Implementation of hook_webform_select_options_info().