chado_feature__seqlen.inc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. class chado_feature__seqlen extends TripalField {
  3. // The default lable for this field.
  4. public static $default_label = 'Sequence length';
  5. // The default description for this field.
  6. public static $default_description = 'A field for calculating the length of a sequence.';
  7. // Add any default settings elements. If you override the globalSettingsForm()
  8. // or the instanceSettingsForm() functions then you need to be sure that
  9. // any settings you want those functions to manage are listed in this
  10. // array.
  11. public static $default_settings = array(
  12. 'chado_table' => '',
  13. 'chado_column' => '',
  14. 'base_table' => '',
  15. 'semantic_web' => '',
  16. );
  17. // Set this to the name of the storage backend that by default will support
  18. // this field.
  19. public static $default_storage = 'field_chado_storage';
  20. /**
  21. * @see TripalField::formatterView()
  22. */
  23. public function formatterView(&$element, $entity_type, $entity, $langcode, $items, $display) {
  24. foreach ($items as $delta => $item) {
  25. $element[$delta] = array(
  26. '#type' => 'markup',
  27. '#markup' => $item['value'],
  28. );
  29. }
  30. }
  31. /**
  32. * @see TripalField::widgetForm()
  33. */
  34. public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
  35. $settings = $this->field['settings'];
  36. $field_name = $this->field['field_name'];
  37. $field_type = $this->field['type'];
  38. $field_table = $this->field['settings']['chado_table'];
  39. $field_column = $this->field['settings']['chado_column'];
  40. $widget['value'] = array(
  41. '#type' => 'value',
  42. '#value' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
  43. );
  44. $widget['feature__seqlen'] = array(
  45. '#type' => 'value',
  46. '#value' => 0,
  47. '#title' => $element['#title'],
  48. '#description' => $element['#description'],
  49. '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
  50. '#delta' => $delta,
  51. // '#element_validate' => array('chado_feature__seqlen_widget_validate'),
  52. );
  53. }
  54. }
  55. /**
  56. * Callback function for validating the chado_feature__seqlen_widget.
  57. */
  58. function chado_feature__seqlen_widget_validate($element, &$form_state) {
  59. $field_name = $element['#parents'][0];
  60. // Get the residues so we can calculate teh length.
  61. //$residues = tripal_chado_get_field_form_values('feature__residues', $form_state, 0, 'feature__residues');
  62. // Remove any white spaces.
  63. if ($residues) {
  64. $residues = preg_replace('/\s/', '', $residues);
  65. tripal_chado_set_field_form_values($field_name, $form_state, strlen($residues), 0, 'feature__seqlen');
  66. }
  67. else {
  68. // Otherwise, remove the seqlen value
  69. tripal_chado_set_field_form_values($field_name, $form_state, '__NULL__', 0, 'feature_seqlen');
  70. }
  71. }