taxrank__infraspecific_taxon_widget.inc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. class taxrank__infraspecific_taxon_widget extends TripalFieldWidget {
  3. // The default lable for this field.
  4. public static $label = 'Infraspecific Taxon';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = array('taxrank__infraspecific_taxon');
  7. /**
  8. *
  9. * @see TripalFieldWidget::form()
  10. */
  11. public function form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
  12. parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
  13. $settings = $this->field['settings'];
  14. $field_name = $this->field['field_name'];
  15. $field_type = $this->field['type'];
  16. $field_table = $this->field['settings']['chado_table'];
  17. $field_column = $this->field['settings']['chado_column'];
  18. $type_id = 0;
  19. if (count($items) > 0 and array_key_exists('organism__type_id', $items[0])) {
  20. $type_id = $items[0]['organism__type_id'];
  21. }
  22. $form['value'] = array(
  23. '#type' => 'value',
  24. '#value' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
  25. );
  26. $cv = tripal_get_default_cv($field_table, $field_column);
  27. $options = array();
  28. if ($cv) {
  29. $options = tripal_get_cvterm_select_options($cv->cv_id);
  30. }
  31. $widget['organism__type_id'] = array(
  32. '#type' => 'select',
  33. '#title' => $element['#title'],
  34. '#description' => $element['#description'],
  35. '#options' => $options,
  36. '#default_value' => $type_id,
  37. '#required' => $element['#required'],
  38. '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
  39. '#delta' => $delta,
  40. );
  41. }
  42. /**
  43. * Performs validation of the widgetForm.
  44. *
  45. * Use this validate to ensure that form values are entered correctly. Note
  46. * this is different from the validate() function which ensures that the
  47. * field data meets expectations.
  48. *
  49. * @param $form
  50. * @param $form_state
  51. */
  52. public function validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
  53. }
  54. /**
  55. *
  56. * @see TripalFieldWidget::submit()
  57. */
  58. public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
  59. }
  60. }