TripalField.inc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /**
  3. * A base class for all Fields supported by the Tripal Chado module.
  4. *
  5. * This class provides all of the necessary functions for a TripalField field.
  6. * It helps simplify and unify the process of creating fields for Tripal. This
  7. * class simply defines the function prototypes. It is up to the class that
  8. * extends this class to implement the functions.
  9. *
  10. * Each module that creates new fields should use the normal Field API hooks
  11. * (e.g. hook_field_info(), hook_field_widget_form(), etc.) to instantiate the
  12. * appropriate TripalField class.
  13. *
  14. * Because of the way Drupal handles callbacks, form validate functions,
  15. * AJAX callbacks and theme functions cannot be part of the implementation of
  16. * this class. Those functions should be added to the bottom of the file
  17. * where the child class is housed..
  18. *
  19. */
  20. class TripalField {
  21. /**
  22. * Provides information about this field.
  23. *
  24. * @return array
  25. * An associative array with key/value pairs compatible with those from
  26. * the hook_field_info() function of the Drupal Field API.
  27. */
  28. public function field_info() {
  29. return array(
  30. );
  31. }
  32. /**
  33. * Provides information about the widget for this field.
  34. *
  35. * @return array
  36. * An associative array with key/value paris compatible with those from the
  37. * hook_field_widget_info() function of the Drupal Field API.
  38. */
  39. public function widget_info() {
  40. return array(
  41. );
  42. }
  43. /**
  44. * Provides information about the formatter for this field.
  45. *
  46. * @return
  47. * An associative array with key/value paris compatible with those from the
  48. * hook_field_formatter_info() function of the Drupal Field API.
  49. *
  50. */
  51. public function formatter_info() {
  52. return array(
  53. );
  54. }
  55. /**
  56. * Provides a summary of the formatter settings.
  57. *
  58. * On the 'Manage Display' page of the content type administration page,
  59. * fields are allowed to provide a settings form. This settings form can
  60. * be used to allow the site admin to define how the field should be
  61. * formatted. The settings are then available for the formatter()
  62. * function of this class. This function provides a text-based description
  63. * of the settings for the site developer to see. It appears on the manage
  64. * display page inline with the field. A field must always return a
  65. * value in this function if the settings form gear button is to appear.
  66. *
  67. * See the hook_field_formatter_settings_summary() function for more
  68. * information.
  69. *
  70. * @param $field
  71. * @param $instance
  72. * @param $view_mode
  73. *
  74. * @return string
  75. * A string that provides a very brief summary of the field settings
  76. * to the user.
  77. *
  78. */
  79. public function formatter_settings_summary($field, $instance, $view_mode) {
  80. }
  81. /**
  82. * Provides the field's setting form.
  83. *
  84. * The settings form appears on the 'Manage Display' page of the content
  85. * type administration page. This function provides the form that will
  86. * appear on that page.
  87. *
  88. * To add a validate function, please create a static function in the
  89. * implementing class, and indicate that this function should be used
  90. * in the form array that is returned by this function.
  91. *
  92. * This form will not be displayed if the formatter_settings_summary()
  93. * function does not return anything.
  94. *
  95. * @param $field
  96. * @param $instance
  97. * @param $view_mode
  98. * @param $form
  99. * @param $form_state
  100. *
  101. * @return
  102. * A Drupal Form array containing the settings form for this field.
  103. */
  104. public function formatter_settings_form($field, $instance,
  105. $view_mode, $form, &$form_state) {
  106. }
  107. /**
  108. * Provides the display for a field
  109. *
  110. * This function provides the display for a field when it is viewed on
  111. * the web page.
  112. *
  113. * @param $element
  114. * @param $entity_type
  115. * @param $entity
  116. * @param $field
  117. * @param $instance
  118. * @param $langcode
  119. * @param $items
  120. * @param $display
  121. *
  122. * @return
  123. * An element array compatible with that returned by the
  124. * hook_field_formatter_view() function.
  125. */
  126. public function formatter_view(&$element, $entity_type, $entity,
  127. $field, $instance, $langcode, $items, $display) {
  128. }
  129. /**
  130. * Provides the form for editing of this field.
  131. *
  132. * This form is diplayed when the user creates a new entity or edits an
  133. * existing entity. If the field is attached to the entity then the form
  134. * provided by this function will be displayed.
  135. *
  136. * @param $widget
  137. * @param $form
  138. * @param $form_state
  139. * @param $field
  140. * @param $instance
  141. * @param $langcode
  142. * @param $items
  143. * @param $delta
  144. * @param $element
  145. *
  146. * @return
  147. * A Drupal form. See the hook_field_widget_form() function for more information.
  148. */
  149. public function widget_form(&$widget, $form, $form_state, $field, $instance,
  150. $langcode, $items, $delta, $element) {
  151. }
  152. /**
  153. * Loads the field values from the underlying data store.
  154. *
  155. * This function is called by the tripal_chado_field_storage_load() for
  156. * each property managed by the field_chado_storage storage type. This is
  157. * an optional hook function that is only needed if the field has
  158. * multiple form elements.
  159. *
  160. * This function must set the value for the field in the entity object. For
  161. * example:
  162. *
  163. * @code
  164. * $field_name = $field['field_name'];
  165. * $field_type = $field['type'];
  166. * $language = 'und';
  167. * $delta = 0;
  168. * $entity->{$field_name}[$language][$delta]['value'] = TRUE;
  169. * @endcode
  170. *
  171. * The field in the entity is an associative array where the first level is
  172. * the field name, followed by the language. The 'und' value indicates
  173. * that the language is undefined and is the default. Next is the 'delta'
  174. * value. For field with a cardinality of 1, the delta value will always be
  175. * 0. For fields with a cardinality greater than 1 then the delta should
  176. * increment for each value. Next is a list of key/value pairs one of which
  177. * should have the name 'value'. The 'value' key should always contain the
  178. * primary value that should be displayed to the user. It can be a single
  179. * value, or an array. Any other number of keys can be present to help
  180. * with the display. These keys also correspond to the names of the form
  181. * fields specified by the widget() function of this class.
  182. *
  183. * @param $field
  184. * @param $entity
  185. * @param $base_table
  186. * @param $record
  187. *
  188. */
  189. public function load($field, $entity, $details) {
  190. }
  191. /**
  192. * Formats the field for dipslay via web services.
  193. *
  194. * The tripal_ws module will look for this funcion to give the field the
  195. * opportunity fo customize the value or array that is present in the
  196. * JSON output of web services.
  197. *
  198. * @return
  199. * A single value or an array of values that should be used for this field.
  200. */
  201. public function ws_formatter($entity_type, $entity, $field, $instance, $items) {
  202. }
  203. /**
  204. * Provides an array that allows Tripal to attach a field to an entity.
  205. *
  206. */
  207. public function attach_info($entity_type, $bundle, $settings) {
  208. }
  209. }