local__contact_formatter.inc

File

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