sio__references_formatter.inc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 = ['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 = [];
  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 = [];
  29. $headers = [];
  30. $rows = [];
  31. ksort($ordered_items);
  32. foreach ($ordered_items as $type => $children) {
  33. $rows[] = [
  34. [
  35. 'data' => ucfirst($type) . '(s)',
  36. 'header' => TRUE,
  37. 'width' => '20%',
  38. ],
  39. theme_item_list([
  40. 'items' => $children,
  41. 'title' => '',
  42. 'type' => 'ul',
  43. 'attributes' => [],
  44. ]),
  45. ];
  46. }
  47. $table = [
  48. 'header' => [],
  49. 'rows' => $rows,
  50. 'attributes' => [
  51. 'id' => 'sio__references-table',
  52. 'class' => 'tripal-data-table',
  53. ],
  54. 'sticky' => FALSE,
  55. 'caption' => "",
  56. 'colgroups' => [],
  57. 'empty' => 'There are no records in this site to which this publiation refers.',
  58. ];
  59. $content = theme_table($table);
  60. $element[0] = [
  61. '#type' => 'markup',
  62. '#markup' => $content,
  63. ];
  64. }
  65. }