so__transcript_formatter.inc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. class so__transcript_formatter extends ChadoFieldFormatter {
  3. // The default lable for this field.
  4. public static $default_label = 'Transcript';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = ['so__transcript'];
  7. /**
  8. *
  9. * @see TripalFieldFormatter::view()
  10. */
  11. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  12. // Get the settings
  13. $settings = $display['settings'];
  14. $headers = ['Transcript Name', 'Identifier', 'Type', 'Location'];
  15. $rows = [];
  16. foreach ($items as $delta => $item) {
  17. if (!$item['value']) {
  18. continue;
  19. }
  20. $transcript = $item['value'];
  21. // Get the field values
  22. $feature_name = $transcript['schema:name'];
  23. $feature_uname = $transcript['data:0842'];
  24. $loc = $transcript['SO:0000735'];
  25. $type = $transcript['rdfs:type'];
  26. // Add a link i there is an entity.
  27. if (array_key_exists('entity', $item['value']) and $item['value']['entity']) {
  28. list($entity_type, $entity_id) = explode(':', $item['value']['entity']);
  29. $feature_name = l($feature_name, "bio_data/" . $entity_id, ['attributes' => ['target' => "_blank"]]);
  30. }
  31. $rows[] = [$feature_name, $feature_uname, $type, $loc];
  32. }
  33. $table = [
  34. 'header' => $headers,
  35. 'rows' => $rows,
  36. 'attributes' => [
  37. 'id' => 'tripal_feature-table-transcripts-object',
  38. 'class' => 'tripal-data-table',
  39. ],
  40. 'sticky' => FALSE,
  41. 'caption' => "",
  42. 'colgroups' => [],
  43. 'empty' => 'This feature has no transcripts',
  44. ];
  45. $content = theme_table($table);
  46. // once we have our table array structure defined, we call Drupal's theme_table()
  47. // function to generate the table.
  48. if (count($items) > 0) {
  49. $element[0] = [
  50. '#type' => 'markup',
  51. '#markup' => $content,
  52. ];
  53. }
  54. }
  55. }