sio__vocabulary_widget.inc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. class sio__vocabulary_widget extends ChadoFieldWidget {
  3. // The default lable for this field.
  4. public static $default_label = 'Vocabulary';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = array('sio__vocabulary');
  7. /**
  8. * @see TripalFieldWidget::form()
  9. */
  10. public function form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
  11. parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
  12. $settings = $this->field['settings'];
  13. $field_name = $this->field['field_name'];
  14. $field_type = $this->field['type'];
  15. $field_table = $this->instance['settings']['chado_table'];
  16. $field_column = $this->instance['settings']['chado_column'];
  17. $cv_id = 0;
  18. $widget['value'] = array(
  19. '#type' => 'value',
  20. '#value' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
  21. );
  22. $widget['chado-' . $field_table . '__cv_id'] = array(
  23. '#type' => 'value',
  24. '#value' => $items[$delta]['chado-' . $field_table . '__cv_id'],
  25. );
  26. $widget['vocabulary_name'] = array(
  27. '#type' => 'item',
  28. '#title' => 'Vocabulary',
  29. '#markup' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
  30. );
  31. }
  32. /**
  33. * @see TripalFieldWidget::validate()
  34. */
  35. public function validate($element, $form, &$form_state, $langcode, $delta) {
  36. $field_name = $this->field['field_name'];
  37. $field_table = $this->instance['settings']['chado_table'];
  38. // Make sure the value is set to the cv_id
  39. $cv_id = $form_state['values'][$field_name][$langcode][0]['chado-' . $field_table . '__cv_id'];
  40. $form_state['values'][$field_name][$langcode][0]['value'] = $cv_id;
  41. }
  42. }