chado_feature__md5checksum.inc 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. class chado_feature__md5checksum extends TripalField {
  3. // The default lable for this field.
  4. public static $default_label = 'Sequence MD5 checksum';
  5. // The default description for this field.
  6. public static $default_description = 'A field for generating MD5 checksum for 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. $content = key_exists('value', $item) ? $item['value'] : '';
  26. $element[$delta] = array(
  27. // We create a render array to produce the desired markup,
  28. '#type' => 'markup',
  29. '#markup' => $content,
  30. );
  31. }
  32. }
  33. /**
  34. * @see TripalField::widgetForm()
  35. */
  36. public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
  37. parent::widgetForm($widget, $form, $form_state, $langcode, $items, $delta, $element);
  38. $settings = $this->field['settings'];
  39. $field_name = $this->field['field_name'];
  40. $field_type = $this->field['type'];
  41. $field_table = $this->field['settings']['chado_table'];
  42. $field_column = $this->field['settings']['chado_column'];
  43. // Get the field defaults.
  44. $md5checksum = '';
  45. if (count($items) > 0 and array_key_exists('chado-feature__md5checksum', $items[0])) {
  46. $md5checksum = $items[0]['chado-feature__md5checksum'];
  47. }
  48. $widget['value'] = array(
  49. '#type' => 'value',
  50. '#value' => $md5checksum,
  51. );
  52. $widget['chado-feature__md5checksum'] = array(
  53. '#type' => 'value',
  54. '#value' => $md5checksum,
  55. );
  56. }
  57. /**
  58. * @see TripalField::widgetFormSubmit()
  59. */
  60. public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
  61. $field = $this->field;
  62. $settings = $field['settings'];
  63. $field_name = $field['field_name'];
  64. $field_type = $field['type'];
  65. $field_table = $field['settings']['chado_table'];
  66. $field_column = $field['settings']['chado_column'];
  67. $items = $form_state['values'][$field_name][$langcode];
  68. // Get the residues so we can calculate teh length.
  69. $residues = $form_state['values']['feature__residues']['und'][0]['chado-feature__residues'];
  70. if ($residues) {
  71. $residues = preg_replace('/\s/', '', $residues);
  72. $form_state['values']['feature__residues']['und'][0]['chado-feature__residues'] = $residues;
  73. $items[0]['chado-feature__md5checksum'] = md5($residues);
  74. }
  75. else {
  76. // Otherwise, remove the md5 value
  77. $items[0]['chado-feature__md5checksum'] = '__NULL__';
  78. }
  79. }
  80. }