ogi__location_on_map_formatter.inc

File

tripal_chado/includes/TripalFields/ogi__location_on_map/ogi__location_on_map_formatter.inc
View source
  1. <?php
  2. class ogi__location_on_map_formatter extends ChadoFieldFormatter {
  3. // The default lable for this field.
  4. public static $default_label = 'Location on Map';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = array('ogi__location_on_map');
  7. /**
  8. *
  9. * @see TripalFieldFormatter::view()
  10. */
  11. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  12. $rows = array();
  13. $headers = array('Map', 'Position', 'Map Description');
  14. foreach ($items as $delta => $item) {
  15. if (!$item['value']) {
  16. continue;
  17. }
  18. $val = $item['value'];
  19. $map_name = $item['value']['data:1274']['schema:name'];
  20. $map_desc = $item['value']['data:1274']['schema:description'];
  21. $position = $item['value']['SIO:000056'];
  22. $rows[] = array(
  23. $map_name,
  24. $position,
  25. $map_desc
  26. );
  27. }
  28. // the $table array contains the headers and rows array as well as other
  29. // options for controlling the display of the table. Additional
  30. // documentation can be found here:
  31. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  32. $table = array(
  33. 'header' => $headers,
  34. 'rows' => $rows,
  35. 'attributes' => array(
  36. 'id' => 'tripal_feature-table-map-positions',
  37. 'class' => 'tripal-data-table'
  38. ),
  39. 'sticky' => FALSE,
  40. 'caption' => '',
  41. 'colgroups' => array(),
  42. 'empty' => 'This are no positions on any maps.',
  43. );
  44. // once we have our table array structure defined, we call Drupal's theme_table()
  45. // function to generate the table.
  46. if (count($items) > 0) {
  47. $element[0] = array(
  48. '#type' => 'markup',
  49. '#markup' => theme_table($table),
  50. );
  51. }
  52. }
  53. }