chado_linker__contact_formatter.inc

File

tripal_chado/includes/TripalFields/chado_linker__contact/chado_linker__contact_formatter.inc
View source
  1. <?php
  2. class chado_linker__contact_formatter extends ChadoFieldFormatter {
  3. // The default lable for this field.
  4. public static $default_label = 'Contacts';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = array('chado_linker__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. $content = '';
  42. if (count($items) > 0) {
  43. $table = array(
  44. 'header' => $headers,
  45. 'rows' => $rows,
  46. 'attributes' => array(
  47. 'id' => 'tripal_linker-table-contact-object',
  48. 'class' => 'tripal-data-table'
  49. ),
  50. 'sticky' => FALSE,
  51. 'caption' => "",
  52. 'colgroups' => array(),
  53. 'empty' => 'There are no contacts available.',
  54. );
  55. $content = theme_table($table);
  56. }
  57. $element[0] = array(
  58. // We create a render array to produce the desired markup,
  59. '#type' => 'markup',
  60. '#markup' => $content,
  61. );
  62. }
  63. }