data__sequence_widget.inc 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. class data__sequence_widget extends TripalFieldWidget {
  3. // The default lable for this field.
  4. public static $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->field['settings']['chado_table'];
  17. $field_column = $this->field['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. * Performs validation of the widgetForm.
  42. *
  43. * Use this validate to ensure that form values are entered correctly. Note
  44. * this is different from the validate() function which ensures that the
  45. * field data meets expectations.
  46. *
  47. * @param $form
  48. * @param $form_state
  49. */
  50. public function validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
  51. }
  52. /**
  53. *
  54. * @see TripalFieldWidget::submit()
  55. */
  56. public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
  57. $field_name = $this->field['field_name'];
  58. // Remove any white spaces.
  59. $residues = isset($form_state['values'][$field_name][$langcode][$delta]['chado-feature__residues']) ? $form_state['values'][$field_name][$langcode][$delta]['chado-feature__residues'] : '';
  60. if ($residues) {
  61. $residues = preg_replace('/\s/', '', $residues);
  62. $form_state['values'][$field_name][$langcode][$delta]['chado-feature__residues'] = $residues;
  63. }
  64. }
  65. }