sep__protocol_formatter.inc

File

tripal_chado/includes/TripalFields/sep__protocol/sep__protocol_formatter.inc
View source
  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]['value']["protocol_id"];
  79. $protocol_name = $items[0]['value']["protocol_name"];
  80. $content = $protocol_name;
  81. list($entity_type, $entity_id) = explode(':', $items[0]['value']['entity_id']);
  82. if ($entity_id) {
  83. $content = l($protocol_name, 'bio_data/' . $entity_id);
  84. }
  85. }
  86. //cardinality for this field is 1
  87. $element[0] = [
  88. '#type' => 'markup',
  89. '#markup' => $content,
  90. ];
  91. }
  92. /**
  93. * Provides a summary of the formatter settings.
  94. *
  95. * This function corresponds to the hook_field_formatter_settings_summary()
  96. * function of the Drupal Field API.
  97. *
  98. * On the 'Manage Display' page of the content type administration page,
  99. * fields are allowed to provide a settings form. This settings form can
  100. * be used to allow the site admin to define how the field should be
  101. * formatted. The settings are then available for the formatter()
  102. * function of this class. This function provides a text-based description
  103. * of the settings for the site developer to see. It appears on the manage
  104. * display page inline with the field. A field must always return a
  105. * value in this function if the settings form gear button is to appear.
  106. *
  107. * See the hook_field_formatter_settings_summary() function for more
  108. * information.
  109. *
  110. * @param $field
  111. * @param $instance
  112. * @param $view_mode
  113. *
  114. * @return string
  115. * A string that provides a very brief summary of the field settings
  116. * to the user.
  117. *
  118. */
  119. public function settingsSummary($view_mode) {
  120. return '';
  121. }
  122. }