function select_with_style_assemble_tree_options_and_attributes in Select with Style 7
Returns a linear list of options, with may be styled like a tree using the also returned option attributes.
Parameters
$terms: Terms belonging to the vocabulary in question.
$prefix: The hierarchy depth prefix to be prepended to each child term label.
$term_transform: The term transform function, e.g., country-to-code, if desired.
Return value
A linear array of option attributes with one key for each key in the options array. The options array is flattened to a linear list.
1 call to select_with_style_assemble_tree_options_and_attributes()
- _select_with_style_options_and_attributes_lists in select_with_style/
select_with_style.module - Build the list option attirbutes in tandem with the option values.
File
- select_with_style/
select_with_style.module, line 369 - select_with_style.module
Code
function select_with_style_assemble_tree_options_and_attributes($terms, $prefix = NULL, $term_transform_callback = NULL) {
$options = array();
$option_attributes = array();
$term_tree = array();
select_with_style_build_term_tree($terms, $term_tree);
select_with_style_flag_child_terms($terms, $term_tree);
foreach ($terms as $term) {
$options[$term->tid] = str_repeat($prefix, $term->depth) . $term->name;
if (!$term->is_leaf || empty($term->parents[0])) {
// Parent, sets the CSS group for itself and its children.
$css_group = select_with_style_term_to_class($term->name, $term_transform_callback);
}
// else keep the $css_group previously set
$first_class = $term->is_leaf ? 'option-child' : 'option-parent';
$option_attributes[$term->tid] = array(
'class' => (empty($css_group) ? $first_class : "{$first_class} group-{$css_group}") . ' tid-' . $term->tid . ' depth-' . $term->depth,
);
}
return array(
$options,
$option_attributes,
);
}