sbo__database_cross_reference_formatter.inc

File

tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_formatter.inc
View source
  1. <?php
  2. class sbo__database_cross_reference_formatter extends ChadoFieldFormatter {
  3. // The default lable for this field.
  4. public static $default_label = 'Cross reference';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = array('sbo__database_cross_reference');
  7. /**
  8. *
  9. * @see TripalFieldFormatter::view()
  10. */
  11. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  12. $content = '';
  13. $field_name = $this->field['field_name'];
  14. $field_type = $this->field['type'];
  15. $field_table = $this->instance['settings']['chado_table'];
  16. $field_column = $this->instance['settings']['chado_column'];
  17. $base_table = $this->instance['settings']['base_table'];
  18. $linker_table = $base_table . '_dbxref';
  19. $dbname_term = chado_get_semweb_term('db', 'name');
  20. $accession_term = chado_get_semweb_term('dbxref', 'accession');
  21. $dburl_term = chado_get_semweb_term('db', 'url');
  22. foreach ($items as $delta => $item) {
  23. if (!$item['value']) {
  24. continue;
  25. }
  26. $content = $item['value'][$dbname_term] . ':' . $item['value'][$accession_term];
  27. if ($item['value'][$dburl_term]) {
  28. $dbxref = chado_get_dbxref(array('dbxref_id' => $item['chado-' . $linker_table . '__dbxref_id']));
  29. $url = chado_get_dbxref_url($dbxref);
  30. $content = l($content, $url, array('attributes' => array('target' => '_blank')));
  31. }
  32. $element[$delta] = array(
  33. '#type' => 'markup',
  34. '#markup' => $content,
  35. );
  36. }
  37. if (count($element) == 0) {
  38. $element[0] = array(
  39. '#type' => 'markup',
  40. '#markup' => 'There are no cross references.',
  41. );
  42. }
  43. }
  44. }