chado_linker__contact_formatter.inc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. class chado_linker__contact_formatter extends TripalFieldFormatter {
  3. // The default lable for this field.
  4. public static $label = 'Contacts';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = array('chado_linker__contact');
  7. // The list of default settings for this formatter.
  8. public static $settings = array();
  9. /**
  10. *
  11. * @see TripalFieldFormatter::settingsForm()
  12. */
  13. public function settingsForm($view_mode, $form, &$form_state) {
  14. }
  15. /**
  16. *
  17. * @see TripalFieldFormatter::view()
  18. */
  19. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  20. // Get the settings
  21. $settings = $display['settings'];
  22. $headers = array('Name', 'Description', 'Type');
  23. $rows = array();
  24. foreach ($items as $delta => $item) {
  25. $contact = $item['value'];
  26. if (!$contact) {
  27. continue;
  28. }
  29. // Get the field values
  30. $contact_name = $contact['name'];
  31. $description = $contact['description'];
  32. $type = $contact['type'];
  33. // Add a link i there is an entity.
  34. if (array_key_exists('entity', $item['value']) and $item['value']['entity']) {
  35. list($entity_type, $entity_id) = explode(':', $item['value']['entity']);
  36. $contact_name = l($contact_name, "bio_data/" . $entity_id, array('attributes' => array('target' => "_blank")));
  37. }
  38. $rows[] = array($contact_name, $description, $type);
  39. }
  40. $table = array(
  41. 'header' => $headers,
  42. 'rows' => $rows,
  43. 'attributes' => array(
  44. 'id' => 'tripal_linker-table-contact-object',
  45. 'class' => 'tripal-data-table'
  46. ),
  47. 'sticky' => FALSE,
  48. 'caption' => "",
  49. 'colgroups' => array(),
  50. 'empty' => 'No contacts available',
  51. );
  52. $content = theme_table($table);
  53. if (count($items) > 0) {
  54. // once we have our table array structure defined, we call Drupal's theme_table()
  55. // function to generate the table.
  56. $element[0] = array(
  57. '#type' => 'markup',
  58. '#markup' => $content,
  59. );
  60. }
  61. }
  62. }