sep__protocol_formatter.inc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * @class
  4. * Purpose:
  5. *
  6. * Display:
  7. * Configuration:
  8. */
  9. class sep__protocol_formatter extends ChadoFieldFormatter {
  10. // The default label for this field.
  11. public static $default_label = 'Protocol';
  12. // The list of field types for which this formatter is appropriate.
  13. public static $field_types = ['sep__protocol'];
  14. // The list of default settings for this formatter.
  15. public static $default_settings = [
  16. 'setting1' => 'default_value',
  17. ];
  18. /**
  19. * Provides the field's setting form.
  20. *
  21. * This function corresponds to the hook_field_formatter_settings_form()
  22. * function of the Drupal Field API.
  23. *
  24. * The settings form appears on the 'Manage Display' page of the content
  25. * type administration page. This function provides the form that will
  26. * appear on that page.
  27. *
  28. * To add a validate function, please create a static function in the
  29. * implementing class, and indicate that this function should be used
  30. * in the form array that is returned by this function.
  31. *
  32. * This form will not be displayed if the formatter_settings_summary()
  33. * function does not return anything.
  34. *
  35. * param $field
  36. * The field structure being configured.
  37. * param $instance
  38. * The instance structure being configured.
  39. * param $view_mode
  40. * The view mode being configured.
  41. * param $form
  42. * The (entire) configuration form array, which will usually have no use
  43. * here. Typically for reference only.
  44. * param $form_state
  45. * The form state of the (entire) configuration form.
  46. *
  47. * @return
  48. * A Drupal Form array containing the settings form for this field.
  49. */
  50. public function settingsForm($view_mode, $form, &$form_state) {
  51. }
  52. /**
  53. * Provides the display for a field
  54. *
  55. * This function corresponds to the hook_field_formatter_view()
  56. * function of the Drupal Field API.
  57. *
  58. * This function provides the display for a field when it is viewed on
  59. * the web page. The content returned by the formatter should only include
  60. * what is present in the $items[$delta]['values] array. This way, the
  61. * contents that are displayed on the page, via webservices and downloaded
  62. * into a CSV file will always be identical. The view need not show all
  63. * of the data in the 'values' array.
  64. *
  65. * @param $element
  66. * @param $entity_type
  67. * @param $entity
  68. * @param $langcode
  69. * @param $items
  70. * @param $display
  71. *
  72. * @return
  73. * An element array compatible with that returned by the
  74. * hook_field_formatter_view() function.
  75. */
  76. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  77. if (count($items) > 0) {
  78. $protocol_id = $items[0]["protocol_chado_id"];
  79. $protocol_name = $items[0]['value']["protocol_name"];
  80. $entity_id = $items[0]['value']['entity_id'];
  81. $content = $protocol_name;
  82. list($entity_type, $entity_id) = explode(':', $items[0]['value']['entity_id']);
  83. if ($entity_id) {
  84. $content = l($protocol_name, 'bio_data/' . $entity_id);
  85. }
  86. }
  87. //cardinality for this field is 1
  88. $element[0] = [
  89. '#type' => 'markup',
  90. '#markup' => $content,
  91. ];
  92. }
  93. /**
  94. * Provides a summary of the formatter settings.
  95. *
  96. * This function corresponds to the hook_field_formatter_settings_summary()
  97. * function of the Drupal Field API.
  98. *
  99. * On the 'Manage Display' page of the content type administration page,
  100. * fields are allowed to provide a settings form. This settings form can
  101. * be used to allow the site admin to define how the field should be
  102. * formatted. The settings are then available for the formatter()
  103. * function of this class. This function provides a text-based description
  104. * of the settings for the site developer to see. It appears on the manage
  105. * display page inline with the field. A field must always return a
  106. * value in this function if the settings form gear button is to appear.
  107. *
  108. * See the hook_field_formatter_settings_summary() function for more
  109. * information.
  110. *
  111. * @param $field
  112. * @param $instance
  113. * @param $view_mode
  114. *
  115. * @return string
  116. * A string that provides a very brief summary of the field settings
  117. * to the user.
  118. *
  119. */
  120. public function settingsSummary($view_mode) {
  121. return '';
  122. }
  123. }