data__sequence_widget.inc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. class data__sequence_widget extends ChadoFieldWidget {
  3. // The default lable for this field.
  4. public static $default_label = 'Sequence';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = array('data__sequence');
  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->instance['settings']['chado_table'];
  17. $field_column = $this->instance['settings']['chado_column'];
  18. // Get the field defaults.
  19. $residues = '';
  20. if (count($items) > 0 and array_key_exists('chado-feature__residues', $items[0])) {
  21. $residues = $items[0]['chado-feature__residues'];
  22. }
  23. if (array_key_exists('values', $form_state)) {
  24. //$residues = tripal_chado_get_field_form_values($field_name, $form_state, 0, 'feature__residues');
  25. }
  26. $widget['value'] = array(
  27. '#type' => 'value',
  28. '#value' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
  29. );
  30. $widget['chado-feature__residues'] = array(
  31. '#type' => 'textarea',
  32. '#title' => $element['#title'],
  33. '#description' => $element['#description'],
  34. '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
  35. '#default_value' => $residues,
  36. '#delta' => $delta,
  37. '#cols' => 30,
  38. );
  39. }
  40. /**
  41. *
  42. * @see TripalFieldWidget::submit()
  43. */
  44. public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
  45. $field_name = $this->field['field_name'];
  46. // Remove any white spaces.
  47. $residues = isset($form_state['values'][$field_name][$langcode][$delta]['chado-feature__residues']) ? $form_state['values'][$field_name][$langcode][$delta]['chado-feature__residues'] : '';
  48. if ($residues) {
  49. $residues = preg_replace('/\s/', '', $residues);
  50. $form_state['values'][$field_name][$langcode][$delta]['chado-feature__residues'] = $residues;
  51. }
  52. }
  53. }