sio__references_formatter.inc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. class sio__references_formatter extends ChadoFieldFormatter {
  3. // The default lable for this field.
  4. public static $default_label = 'References';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = array('sio__references');
  7. /**
  8. *
  9. * @see TripalFieldFormatter::view()
  10. */
  11. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  12. $field_name = $this->field['field_name'];
  13. $chado_table = $this->instance['settings']['chado_table'];
  14. // First, organize the values by their types.
  15. $ordered_items = array();
  16. foreach ($items as $delta => $item) {
  17. $type = isset($item['value']['rdfs:type']) ? $item['value']['rdfs:type'] : '';
  18. $entity = isset($item['value']['entity']) ? $item['value']['entity'] : '';
  19. $name = isset($item['value']['schema:name']) ? $item['value']['schema:name'] : '';
  20. $identifier = isset($item['value']['data:0842']) ? $item['value']['data:0842'] : '';
  21. if ($entity) {
  22. list($entity_type, $entity_id) = explode(':', $entity);
  23. $name = l(strip_tags($name), 'bio_data/' . $entity_id);
  24. }
  25. $ordered_items[ucfirst($type)][] = $name;
  26. }
  27. // Reorder the list so it's compatible with theming a list.
  28. $list_items = array();
  29. $headers = array();
  30. $rows = array();
  31. ksort($ordered_items);
  32. foreach ($ordered_items as $type => $children) {
  33. $rows[] = array(
  34. array(
  35. 'data' => ucfirst($type) . '(s)',
  36. 'header' => TRUE,
  37. 'width' => '20%',
  38. ),
  39. theme_item_list(array(
  40. 'items' => $children,
  41. 'title' => '',
  42. 'type' => 'ul',
  43. 'attributes' => array(),
  44. )),
  45. );
  46. }
  47. $table = array(
  48. 'header' => array(),
  49. 'rows' => $rows,
  50. 'attributes' => array(
  51. 'id' => 'sio__references-table',
  52. 'class' => 'tripal-data-table'
  53. ),
  54. 'sticky' => FALSE,
  55. 'caption' => "",
  56. 'colgroups' => array(),
  57. 'empty' => 'There are no records in this site to which this publiation refers.',
  58. );
  59. $content = theme_table($table);
  60. $element[0] = array(
  61. '#type' => 'markup',
  62. '#markup' => $content,
  63. );
  64. }
  65. }