Created
January 4, 2017 19:44
-
-
Save daggerhart/b4aeaecd642d3f839740f0d9fa3d1bfc to your computer and use it in GitHub Desktop.
Drupal 7 Webform dynamic select option list for providing taxonomy terms as an option list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_webform_select_options_info(). | |
*/ | |
function MODULE_webform_select_options_info() { | |
$items = array(); | |
$vocabularies = taxonomy_get_vocabularies(); | |
foreach( $vocabularies as $vocabulary ){ | |
$items['vocabulary_'.$vocabulary->machine_name] = array( | |
'title' => 'Vocabulary: ' . $vocabulary->name, | |
'options callback' => 'vocabulary_terms_webform_select_options_callback', | |
'options arguments' => array( | |
'vid' => $vocabulary->vid, | |
), | |
); | |
} | |
return $items; | |
} | |
/** | |
* Option callback for vocabulary select options | |
* | |
* @param $component | |
* @param $flat | |
* @param $arguments | |
* | |
* @return array | |
*/ | |
function vocabulary_terms_webform_select_options_callback( $component, $flat, $arguments ){ | |
$options = array(); | |
$terms = entity_load('taxonomy_term', FALSE, array('vid' => $arguments['vid'])); | |
foreach( $terms as $term ){ | |
$options[ $term->tid ] = $term->name; | |
} | |
return $options; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment