so__transcript_formatter.inc 2.2 KB

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