You are here

function _cshs_get_options in Client-side Hierarchical Select 7

Collects the options for a field.

2 calls to _cshs_get_options()
cshs_field_widget_form in ./cshs.module
Implements hook_field_widget_form().
cshs_handler_filter_term_node_tid::value_form in includes/handlers/cshs_handler_filter_term_node_tid.inc
Define the actual exposed form.

File

./cshs.module, line 186
A simple clientside hierarchical select widget for taxonomy terms.

Code

function _cshs_get_options($vocab_name, $parent = 0) {

  // Setup properties directly instead of calling _options_properties().
  $properties = array(
    'filter_xss' => FALSE,
    'strip_tags' => TRUE,
    'strip_tags_and_unescape' => TRUE,
    'empty_option' => 'option_none',
    'optgroups' => FALSE,
  );

  // Get all terms as options.
  $options = array();
  if ($vocabulary = taxonomy_vocabulary_machine_name_load($vocab_name)) {
    if ($terms = taxonomy_get_tree($vocabulary->vid, $parent)) {
      if (module_exists('i18n_taxonomy')) {

        // Localize terms.
        $terms = i18n_taxonomy_localize_terms($terms);
      }
      foreach ($terms as $term) {
        $options[$term->tid] = array(
          'name' => str_repeat('- ', $term->depth) . $term->name,
          'parent_tid' => _cshs_shift_parent($term->parents),
        );
      }
    }
  }

  // Sanitize the options.
  _options_prepare_options($options, $properties);

  // Always add an empty option.
  _cshs_add_none_option($options);
  return $options;
}