You are here

function node_field_taxonomy_widget in Node Field 7.2

Widget for taxonomy field.

1 string reference to 'node_field_taxonomy_widget'
node_field_types_info in includes/node_field.field.inc
Node field types info.

File

includes/node_field.field.inc, line 500
Field types, settings, widget and formatters.

Code

function node_field_taxonomy_widget($node_field) {
  if (empty($node_field['settings']['vocs'])) {
    return;
  }
  $wrapper_id = 'node-field-value-wrapper-' . $node_field['id'];
  $terms_options = [];
  $terms = taxonomy_get_tree($node_field['settings']['vocs']);
  foreach ($terms as $term) {
    $terms_options[$term->tid] = $term->name;
  }
  $form = [
    '#type' => 'select',
    '#title' => $node_field['title'],
    '#options' => $terms_options,
    '#default_value' => $node_field['value'],
    '#prefix' => '<div id="' . $wrapper_id . '">',
    '#suffix' => '</div>',
    '#disabled' => empty($node_field['settings']['vocs']) ? TRUE : FALSE,
  ];
  return $form;
}