sep__protocol_widget.inc 5.2 KB

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