remote__data_widget.inc 5.4 KB

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