I would like to create rated inteterests for each user. Until now what I have is a taxonomy term vocabulary defined and a field in the user account attached to this vocabulary. Until here what a user can do is to check or not each term of the vocabulary, using the widget options_list. What I would like to do is to let the user select the level (0-10) of preference for each term.
I've tried to create a custom field with two columns, tid and value, then linking each tid with taxonomy term in hook_field_widget_form, but no luck as I'm not an expert in fields, so I'm confused about how to implement:
/**
* Implements hook_field_widget_form().
*/
function taxonomy_value_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
$tids = isset($items[$delta]['tid']) ? $items[$delta]['tid'] : array();
$values = isset($items[$delta]['value']) ? $items[$delta]['value'] : array();
$element += array(
'#delta' => $delta,
);
switch ($instance['widget']['type']) {
case 'taxonomy_value_widget':
if ($vocabulary = taxonomy_vocabulary_machine_name_load('tags')) {
if ($terms = taxonomy_get_tree($vocabulary->vid)) {
foreach ($terms as $term) {
if ($term->depth == 0) {
$element[$term->tid] = array(
'#markup' => '</br><strong>' . $term->name . '</strong>',
);
} else {
$element[$term->tid]['term'] = array(
'#markup' => '</br>' . $term->name,
);
$element[$term->tid]['tid'] = array(
'#type' => 'value',
'#value' => $term->tid,
);
$element[$term->tid]['value'] = array(
'#type' => 'textfield',
'#value' => in_array($term->tid, $values) ? $values[$term->tid] : 5,
);
}
}
}
}
break;
}
return $element;
}