custom_field.rst 6.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. Creating a Custom Field
  2. =======================
  3. The most common way that new content will be added to an existing site is by creating new fields, or field displays. In Tripal v2 customizations were added by editing PHP templates files. These template files were relatively easy to create and customize, but they provided less flexibility and did not integrate well with other Drupal features such as GUI-based page layout and Drupal Views. Tripal v3 fields now provide this flexibility. They also support data exchange and data collections!
  4. By default Tripal v3 provides many fields for display of Chado data. However, you may find that these fields do not display data as you want, or you want to display data that the current fields do not already provide. This section of the Handbook describes how to create new fields that are integrated into the display, search and exchange abilities of both Drupal and Tripal.
  5. If you are already familiar with Drupal fields you may be aware of the API functions and hooks that Drupal provides. However, for the quantity of fields needed to support biological data, the Drupal API hooks quickly become overwhelming. Additionally, documentation for fields in the Drupal API can sometimes be difficult to discover when first working with fields. Therefore, Tripal provides several new PHP classes to simplify creation of fields and to consolidate all functionality into one easy to find set of files. To develop new fields you should be somewhat familiar working with PHP's Object-Oriented Classes. The new classes provided by Tripal are these:
  6. +----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  7. | Class Name | Description |
  8. +----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  9. | TripalField | The TripalField class provides the basic information about a new field. It provides loaders for extracting data from the database and functions for querying data managed by the field. |
  10. +----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  11. | TripalFieldWidget | The TripalFieldWidget class provides the necessary form elements when editing an Entity to allow the end-user to edit the value of the field (if desired). It provides the necessary validators and submitter functions. |
  12. +----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  13. | TripalFieldFormatter | The TripalFieldFormatter class provides the visualization of the field when viewed on the page. |
  14. +----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  15. | ChadoField | The ChadoField class extends the TripalField class and provides the necessary settings to allow the field to map entities to data in Chado |
  16. +----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  17. | ChadoFieldWidget | Extends the TripalFieldWidget class but currently provides no additional functionality. Use this class when working with Chado data to ensure future backwards compatibility. |
  18. +----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  19. | ChadoFieldFormatter | Extends the TriplFieldFormatter class but currently provides no additional functionality. Use this class when working with Chado data to ensure future backwards compatibility. |
  20. +----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. The process for creating a custom field are as follows:
  22. * Determine the controlled vocabulary term that best describes the data your field will create.
  23. * Decide if you need the Chado field classes or the base Tripal field classes. If you intend to work with data housed in Chado then you should use the Chado field classes.
  24. * Decide if you want to build your class manually from the ground up or speed development by using the Staton Lab Fields Generator tool.
  25. * Create new implementations of classes that extend those listed in the table above. If you implement the functions properly your field is plug-and-play! Tripal will find it and be able to use it.
  26. The rest of this section will walk you through these steps.
  27. .. toctree::
  28. :maxdepth: 2
  29. :caption: Table of Contents
  30. custom_field/select_vocab_terms
  31. custom_field/manual_field_creation
  32. custom_field/custom_widget
  33. custom_field/custom_formatter
  34. custom_field/ajax_custom_formatter
  35. custom_field/create_instance
  36. custom_field/tripal_field_generator