kvproperty.inc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. *
  4. * @param unknown $entity_type
  5. * @param unknown $entity
  6. * @param unknown $field
  7. * @param unknown $instance
  8. * @param unknown $langcode
  9. * @param unknown $items
  10. * @param unknown $display
  11. */
  12. function tripal_fields_kvproperty_formatter(&$element, $entity_type, $entity, $field,
  13. $instance, $langcode, $items, $display) {
  14. $content = '';
  15. foreach ($items as $delta => $item) {
  16. $content = key_exists('value', $item) ? $item['value'] : '';
  17. $element[$delta] = array(
  18. '#type' => 'markup',
  19. '#markup' => $content,
  20. );
  21. }
  22. }
  23. /**
  24. *
  25. * @param unknown $field_name
  26. * @param unknown $widget
  27. * @param unknown $form
  28. * @param unknown $form_state
  29. * @param unknown $field
  30. * @param unknown $instance
  31. * @param unknown $langcode
  32. * @param unknown $items
  33. * @param unknown $delta
  34. * @param unknown $element
  35. */
  36. function tripal_fields_kvproperty_widget(&$widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element) {
  37. $chado_entity = $form['#entity']->chado_entity;
  38. $field_name = $field['field_name'];
  39. $matches = array();
  40. preg_match('/(.*?)__(\d+)/', $field_name, $matches);
  41. // If the field name is not properly formatted then we can't tell what
  42. // table and type this is. So just return.
  43. if (count($matches) != 3) {
  44. return $widget;
  45. }
  46. $table_name = $matches[1];
  47. $cvterm_id = $matches[2];
  48. // Get the name of the pkey field for this property table.
  49. $schema = chado_get_schema($table_name);
  50. $pkey = $schema['primary key'][0];
  51. // Get the name of the FK field that links to the base data table.
  52. $schema = chado_get_schema($chado_entity->data_table);
  53. $fk = $schema['primary key'][0];
  54. $pkey_value = '';
  55. $fk_value = $chado_entity->record_id;
  56. // The group of elements all-together need some extra functionality
  57. // after building up the full list (like draggable table rows).
  58. $widget['#theme'] = 'field_multiple_value_form';
  59. $widget['#title'] = $element['#title'];
  60. $widget['#description'] = $element['#description'];
  61. $widget['#field_name'] = $element['#field_name'];
  62. $widget['#language'] = $element['#language'];
  63. $widget['#weight'] = isset($element['#weight']) ? $element['#weight'] : 0;
  64. $widget['#element_validate'] = array('tripal_fields_kvproperty_widget_validate');
  65. $widget['#cardinality'] = 1;
  66. $widget['value'][$delta] = array(
  67. '#type' => 'hidden',
  68. '#value' => $pkey_value,
  69. );
  70. $widget[$table_name . '__' . $pkey] = array(
  71. '#type' => 'hidden',
  72. '#value' => $pkey_value,
  73. );
  74. $widget[$table_name . '__' . $fk] = array(
  75. '#type' => 'hidden',
  76. '#value' => $fk_value,
  77. );
  78. $widget[$table_name . '__value'] = array(
  79. '#type' => 'textfield',
  80. '#default_value' => !empty($items) ? $items[0] : '',
  81. );
  82. $widget[$table_name . '__type_id'] = array(
  83. '#type' => 'hidden',
  84. '#value' => $cvterm_id,
  85. );
  86. $widget[$table_name . '__rank'] = array(
  87. '#type' => 'hidden',
  88. '#value' => $delta,
  89. );
  90. return $widget;
  91. }
  92. /**
  93. *
  94. * @param unknown $form
  95. * @param unknown $form_state
  96. */
  97. function tripal_fields_kvproperty_widget_form_ajax_callback($form, $form_state) {
  98. $field_name = $form_state['triggering_element']['#parents'][0];
  99. return $form[$field_name];
  100. }
  101. /**
  102. * Callback function for validating the tripal_fields_kvproperty_widget.
  103. */
  104. function tripal_fields_kvproperty_widget_validate($element, &$form_state) {
  105. $field_name = $element['#field_name'];
  106. }
  107. /**
  108. * Callback function for submitting the tripal_fields_kvproperty_widget.
  109. */
  110. function tripal_fields_kvproperty_widget_submit($element, &$form_state) {
  111. }