chado_feature__seqlen.inc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. );
  16. // Set this to the name of the storage backend that by default will support
  17. // this field.
  18. public static $default_storage = 'field_chado_storage';
  19. /**
  20. * @see TripalField::formatterView()
  21. */
  22. public function formatterView(&$element, $entity_type, $entity, $langcode, $items, $display) {
  23. foreach ($items as $delta => $item) {
  24. $element[$delta] = array(
  25. '#type' => 'markup',
  26. '#markup' => $item['value'],
  27. );
  28. }
  29. }
  30. /**
  31. * @see TripalField::widgetForm()
  32. */
  33. public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
  34. $field_name = $this->field['field_name'];
  35. $field_type = $this->field['type'];
  36. $field_table = $this->instance['settings']['chado_table'];
  37. $field_column = $this->instance['settings']['chado_column'];
  38. $widget['value'] = array(
  39. '#type' => 'value',
  40. '#value' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
  41. );
  42. $widget['chado-feature__seqlen'] = array(
  43. '#type' => 'value',
  44. '#value' => 0,
  45. '#title' => $element['#title'],
  46. '#description' => $element['#description'],
  47. '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
  48. '#delta' => $delta,
  49. );
  50. }
  51. /**
  52. * @see TripalField::widgetFormSubmit()
  53. */
  54. public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
  55. $field_name = $this->field['field_name'];
  56. $field_type = $this->field['type'];
  57. $field_table = $this->instance['settings']['chado_table'];
  58. $field_column = $this->instance['settings']['chado_column'];
  59. // Get the residues so we can calculate teh length.
  60. $residues = $form_state['values']['feature__residues']['und'][0]['chado-feature__residues'];
  61. // Remove any white spaces.
  62. if ($residues) {
  63. $residues = preg_replace('/\s/', '', $residues);
  64. $form_state['values']['feature__residues']['und'][0]['chado-feature__residues'] = $residues;
  65. $items[0]['chado-feature__seqlen'] = strlen($residues);
  66. }
  67. else {
  68. $items[0]['chado-feature__seqlen'] = '__NULL__';
  69. }
  70. }
  71. }