so__transcript_formatter.inc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. class so__transcript_formatter extends ChadoFieldFormatter {
  3. // The default label 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. dpm($this->instance['settings']);
  15. $headers = ['Transcript Name', 'Identifier', 'Type', 'Location'];
  16. $rows = [];
  17. foreach ($items as $delta => $item) {
  18. if (!$item['value']) {
  19. continue;
  20. }
  21. $transcript = $item['value'];
  22. // Get the field values
  23. $feature_name = $transcript['schema:name'];
  24. $feature_uname = $transcript['data:0842'];
  25. $loc = $transcript['SO:0000735'];
  26. $type = $transcript['rdfs:type'];
  27. // Add a link if there is an entity.
  28. if (array_key_exists('entity', $item['value']) and $item['value']['entity']) {
  29. list($entity_type, $entity_id) = explode(':', $item['value']['entity']);
  30. $feature_name = l($feature_name, "bio_data/" . $entity_id, ['attributes' => ['target' => "_blank"]]);
  31. }
  32. $rows[] = [$feature_name, $feature_uname, $type, $loc];
  33. }
  34. $table = [
  35. 'header' => $headers,
  36. 'rows' => $rows,
  37. 'attributes' => [
  38. 'id' => 'tripal_feature-table-transcripts-object',
  39. 'class' => 'tripal-data-table',
  40. ],
  41. 'sticky' => FALSE,
  42. 'caption' => "",
  43. 'colgroups' => [],
  44. 'empty' => 'This feature has no transcripts',
  45. ];
  46. $content = theme_table($table);
  47. // once we have our table array structure defined, we call Drupal's theme_table()
  48. // function to generate the table.
  49. if (count($items) > 0) {
  50. $element[0] = [
  51. '#type' => 'markup',
  52. '#markup' => $content,
  53. ];
  54. }
  55. }
  56. }