chado_feature__seqlen.inc 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. $field_name = $this->field['field_name'];
  36. $field_type = $this->field['type'];
  37. $field_table = $this->field['settings']['chado_table'];
  38. $field_column = $this->field['settings']['chado_column'];
  39. $widget['value'] = array(
  40. '#type' => 'value',
  41. '#value' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
  42. );
  43. $widget['chado-feature__seqlen'] = array(
  44. '#type' => 'value',
  45. '#value' => 0,
  46. '#title' => $element['#title'],
  47. '#description' => $element['#description'],
  48. '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
  49. '#delta' => $delta,
  50. );
  51. }
  52. /**
  53. * @see TripalField::widgetFormSubmit()
  54. */
  55. public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
  56. $field_name = $this->field['field_name'];
  57. $field_type = $this->field['type'];
  58. $field_table = $this->field['settings']['chado_table'];
  59. $field_column = $this->field['settings']['chado_column'];
  60. $items = $form_state['values'][$field_name][$langcode];
  61. // Get the residues so we can calculate teh length.
  62. $residues = $form_state['values']['feature__residues']['und'][0]['chado-feature__residues'];
  63. // Remove any white spaces.
  64. if ($residues) {
  65. $residues = preg_replace('/\s/', '', $residues);
  66. $form_state['values']['feature__residues']['und'][0]['chado-feature__residues'] = $residues;
  67. $items[0]['chado-feature__seqlen'] = strlen($residues);
  68. }
  69. else {
  70. $items[0]['chado-feature__seqlen'] = '__NULL__';
  71. }
  72. }
  73. }