chado_feature__seqlen.inc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
  55. // Get the residues so we can calculate teh length.
  56. //$residues = tripal_chado_get_field_form_values('feature__residues', $form_state, 0, 'feature__residues');
  57. // Remove any white spaces.
  58. if ($residues) {
  59. $residues = preg_replace('/\s/', '', $residues);
  60. tripal_chado_set_field_form_values($field_name, $form_state, strlen($residues), 0, 'feature__seqlen');
  61. }
  62. else {
  63. // Otherwise, remove the seqlen value
  64. tripal_chado_set_field_form_values($field_name, $form_state, '__NULL__', 0, 'feature_seqlen');
  65. }
  66. }
  67. }