sio__references_formatter.inc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. // Do we have an empty list? If so, just return.
  15. if (!$items[0]['value']) {
  16. return;
  17. }
  18. // First, organize the values by their types.
  19. $ordered_items = [];
  20. foreach ($items as $delta => $item) {
  21. $type = isset($item['value']['rdfs:type']) ? $item['value']['rdfs:type'] : '';
  22. $entity = isset($item['value']['entity']) ? $item['value']['entity'] : '';
  23. $name = isset($item['value']['schema:name']) ? $item['value']['schema:name'] : '';
  24. $identifier = isset($item['value']['data:0842']) ? $item['value']['data:0842'] : '';
  25. if ($entity) {
  26. list($entity_type, $entity_id) = explode(':', $entity);
  27. $name = l(strip_tags($name), 'bio_data/' . $entity_id);
  28. }
  29. $ordered_items[ucfirst($type)][] = $name;
  30. }
  31. // Reorder the list so it's compatible with theming a list.
  32. $list_items = [];
  33. $headers = [];
  34. $rows = [];
  35. ksort($ordered_items);
  36. foreach ($ordered_items as $type => $children) {
  37. $rows[] = [
  38. [
  39. 'data' => ucfirst($type) . '(s)',
  40. 'header' => TRUE,
  41. 'width' => '20%',
  42. ],
  43. theme_item_list([
  44. 'items' => $children,
  45. 'title' => '',
  46. 'type' => 'ul',
  47. 'attributes' => [],
  48. ]),
  49. ];
  50. }
  51. $table = [
  52. 'header' => [],
  53. 'rows' => $rows,
  54. 'attributes' => [
  55. 'id' => 'sio__references-table',
  56. 'class' => 'tripal-data-table',
  57. ],
  58. 'sticky' => FALSE,
  59. 'caption' => "",
  60. 'colgroups' => [],
  61. 'empty' => 'There are no records in this site to which this publiation refers.',
  62. ];
  63. $content = theme_table($table);
  64. $element[0] = [
  65. '#type' => 'markup',
  66. '#markup' => $content,
  67. ];
  68. }
  69. }