sio__references_formatter.inc 2.3 KB

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