local__contact_formatter.inc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. class local__contact_formatter extends ChadoFieldFormatter {
  3. // The default label 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 = ['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 = ['Name', 'Description', 'Type'];
  24. $rows = [];
  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, ['attributes' => ['target' => "_blank"]]);
  38. }
  39. $rows[] = [$contact_name, $description, $type];
  40. }
  41. $table = [
  42. 'header' => $headers,
  43. 'rows' => $rows,
  44. 'attributes' => [
  45. 'id' => 'tripal_linker-table-contact-object',
  46. 'class' => 'tripal-data-table',
  47. ],
  48. 'sticky' => FALSE,
  49. 'caption' => "",
  50. 'colgroups' => [],
  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] = [
  58. '#type' => 'markup',
  59. '#markup' => $content,
  60. ];
  61. }
  62. }
  63. }