TripalField.inc 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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, validate functions and theme functions cannot be part of
  16. * the implementation of this class. Those functions should be added to
  17. * the bottom of the file 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. The content returned by the formatter should only include
  112. * what is present in the $items[$delta]['values] array. This way, the
  113. * contents that are displayed on the page, via webservices and downloaded
  114. * into a CSV file will always be identical. It should also include all of
  115. * the data in the $items[$delta]['values] array so that all the data is
  116. * present everywhere.
  117. *
  118. * @param $element
  119. * @param $entity_type
  120. * @param $entity
  121. * @param $field
  122. * @param $instance
  123. * @param $langcode
  124. * @param $items
  125. * @param $display
  126. *
  127. * @return
  128. * An element array compatible with that returned by the
  129. * hook_field_formatter_view() function.
  130. */
  131. public function formatter_view(&$element, $entity_type, $entity,
  132. $field, $instance, $langcode, $items, $display) {
  133. }
  134. /**
  135. * Provides the form for editing of this field.
  136. *
  137. * This form is diplayed when the user creates a new entity or edits an
  138. * existing entity. If the field is attached to the entity then the form
  139. * provided by this function will be displayed.
  140. *
  141. * @param $widget
  142. * @param $form
  143. * @param $form_state
  144. * @param $field
  145. * @param $instance
  146. * @param $langcode
  147. * @param $items
  148. * @param $delta
  149. * @param $element
  150. *
  151. * @return
  152. * A Drupal form. See the hook_field_widget_form() function for more information.
  153. */
  154. public function widget_form(&$widget, $form, $form_state, $field, $instance,
  155. $langcode, $items, $delta, $element) {
  156. }
  157. /**
  158. * Loads the field values from the underlying data store.
  159. *
  160. * This function is called by the tripal_chado_field_storage_load() for
  161. * each property managed by the field_chado_storage storage type. This is
  162. * an optional hook function that is only needed if the field has
  163. * multiple form elements.
  164. *
  165. * This function must set the value for the field in the entity object. For
  166. * example:
  167. *
  168. * @code
  169. * $field_name = $field['field_name'];
  170. * $field_type = $field['type'];
  171. * $language = 'und';
  172. * $delta = 0;
  173. * $entity->{$field_name}[$language][$delta]['value'] = TRUE;
  174. * @endcode
  175. *
  176. * The field in the entity is an associative array where the first level is
  177. * the field name, followed by the language. The 'und' value indicates
  178. * that the language is undefined and is the default. Next is the 'delta'
  179. * value. For field with a cardinality of 1, the delta value will always be
  180. * 0. For fields with a cardinality greater than 1 then the delta should
  181. * increment for each value. Next is a list of key/value pairs one of which
  182. * should have the name 'value'. The 'value' key should always contain the
  183. * primary value that should be displayed to the user. It can be a single
  184. * value, or an array. Any other number of keys can be present to help
  185. * with the display. These keys also correspond to the names of the form
  186. * fields specified by the widget() function of this class.
  187. *
  188. * @param $field
  189. * @param $entity
  190. * @param $base_table
  191. * @param $record
  192. *
  193. * @return
  194. * An array of the following format:
  195. * $entity->{$field_name}['und'][0]['value'] = $value;
  196. * where:
  197. * - $entity is the enity object to which this field is attached.
  198. * - $field_name is the name of this field
  199. * - 'und' is the language code (in this case 'und' == undefined)
  200. * - 0 is the cardinality. Increment by 1 when more than one item is
  201. * available.
  202. * - 'value' is the key indicating the value of this field. It should
  203. * always be set. The value of the 'value' key will be the contents
  204. * used for web services and for downloadable content. The value
  205. * should be of the follow format types: 1) A single value (text,
  206. * numeric, etc.) 2) An array of key value pair. 3) If multiple entries
  207. * then cardinality should incremented and format types 1 and 2 should
  208. * be used for each item.
  209. * The array may contain as many other keys at the same level as 'value'
  210. * but those keys are for internal field use and are not considered the
  211. * value of the field.
  212. *
  213. *
  214. */
  215. public function load($field, $entity, $details) {
  216. }
  217. /**
  218. * Provides a form for the 'Field Settings' of the field management page.
  219. *
  220. * This is an optional hook function and is similar to the
  221. * hook_field_settings_form function().
  222. *
  223. * @param $field
  224. * The field structure being configured.
  225. * @param $instance
  226. * The instance structure being configured.
  227. * @param $has_data
  228. * TRUE if the field already has data, FALSE if not.
  229. */
  230. public function settings_form($field, $instance, $has_data) {
  231. }
  232. /**
  233. * Provides an array that allows Tripal to attach a field to an entity.
  234. *
  235. */
  236. public function attach_info($entity_type, $bundle, $settings) {
  237. }
  238. }