WebServicesFieldWidget.inc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * @class
  4. * Purpose:
  5. *
  6. * Allowing edit?
  7. * Data:
  8. * Assumptions:
  9. */
  10. class WebServicesFieldWidget extends TripalFieldWidget {
  11. /*
  12. // The default label for this field.
  13. public static $default_label = '';
  14. // The list of field types for which this formatter is appropriate.
  15. //public static $field_types = array('no_widget');
  16. /**
  17. * Provides the form for editing of this field.
  18. *
  19. * This function corresponds to the hook_field_widget_form()
  20. * function of the Drupal Field API.
  21. *
  22. * This form is diplayed when the user creates a new entity or edits an
  23. * existing entity. If the field is attached to the entity then the form
  24. * provided by this function will be displayed.
  25. *
  26. * At a minimum, the form must have a 'value' element. For Tripal, the
  27. * 'value' element of a field always corresponds to the value that is
  28. * presented to the end-user either directly on the page (with formatting)
  29. * or via web services, or some other mechanism. However, the 'value' is
  30. * sometimes not enough for a field. For example, the Tripal Chado module
  31. * maps fields to table columns and sometimes those columns are foreign keys
  32. * therefore, the Tripal Chado modules does not just use the 'value' but adds
  33. * additional elements to help link records via FKs. But even in this case
  34. * the 'value' element must always be present in the return form and in such
  35. * cases it's value should be set equal to that added in the 'load' function.
  36. *
  37. * @param $widget
  38. * @param $form
  39. * The form structure where widgets are being attached to. This might be a
  40. * full form structure, or a sub-element of a larger form.
  41. * @param $form_state
  42. * An associative array containing the current state of the form.
  43. * @param $langcode
  44. * The language associated with $items.
  45. * @param $items
  46. * Array of default values for this field.
  47. * @param $delta
  48. * The order of this item in the array of subelements (0, 1, 2, etc).
  49. * @param $element
  50. * A form element array containing basic properties for the widget:
  51. * - #entity_type: The name of the entity the field is attached to.
  52. * - #bundle: The name of the field bundle the field is contained in.
  53. * - #field_name: The name of the field.
  54. * - #language: The language the field is being edited in.
  55. * - #field_parents: The 'parents' space for the field in the form. Most
  56. * widgets can simply overlook this property. This identifies the location
  57. * where the field values are placed within $form_state['values'], and is
  58. * used to access processing information for the field through the
  59. * field_form_get_state() and field_form_set_state() functions.
  60. * - #columns: A list of field storage columns of the field.
  61. * - #title: The sanitized element label for the field instance, ready for
  62. * output.
  63. * - #description: The sanitized element description for the field instance,
  64. * ready for output.
  65. * - #required: A Boolean indicating whether the element value is required;
  66. * for required multiple value fields, only the first widget's values are
  67. * required.
  68. * - #delta: The order of this item in the array of subelements; see
  69. * $delta above
  70. public function form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
  71. parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
  72. }
  73. /**
  74. * Performs validation of the widgetForm.
  75. *
  76. * Use this validate to ensure that form values are entered correctly.
  77. * The 'value' key of this field must be set in the $form_state['values']
  78. * array anytime data is entered by the user. It may be the case that there
  79. * are other fields for helping select a value. In the end those helper
  80. * fields must be used to set the 'value' field.
  81. public function validate($element, $form, &$form_state, $langcode, $delta) {
  82. }
  83. /**
  84. * Performs extra commands when the entity form is submitted.
  85. *
  86. * Drupal typically does not provide a submit hook for fields. The
  87. * TripalField provides one to allow for behind-the-scenes actions to
  88. * occur. This function should never be used for updates, deletes or
  89. * inserts for the Chado table associated with the field. Rather, the
  90. * storage backend should be allowed to handle inserts, updates deletes.
  91. * However, it is permissible to perform inserts, updates or deletions within
  92. * Chado using this function. Those operations can be performed if needed but
  93. * on other tables not directly associated with the field.
  94. *
  95. * An example is the chado.feature_synonym table. The chado_linker__synonym
  96. * field allows the user to provide a brand new synonynm and it must add it
  97. * to the chado.synonym table prior to the record in the
  98. * chado.feature_synonym table. This insert occurs in the widgetFormSubmit
  99. * function.
  100. *
  101. * @param $entity_type
  102. * The type of $entity.
  103. * @param $entity
  104. * The entity for the operation.
  105. * @param $field
  106. * The field structure for the operation.
  107. * @param $instance
  108. * The instance structure for $field on $entity's bundle.
  109. * @param $langcode
  110. * The language associated with $items.
  111. * @param $items
  112. * $entity->{$field['field_name']}[$langcode], or an empty array if unset.
  113. * @param $form
  114. * The submitted form array.
  115. * @param $form_state.
  116. * The form state array.
  117. public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
  118. }
  119. */
  120. }