local__source_data_formatter.inc

File

tripal_chado/includes/TripalFields/local__source_data/local__source_data_formatter.inc
View source
  1. <?php
  2. class local__source_data_formatter extends ChadoFieldFormatter {
  3. // The default lable for this field.
  4. public static $default_label = 'Data Source';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = array('local__source_data');
  7. /**
  8. * @see TripalFieldFormatter::view()
  9. */
  10. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  11. $sourcename_term = chado_get_semweb_term('analysis', 'sourcename');
  12. $sourceversion_term = chado_get_semweb_term('analysis', 'sourceversion');
  13. $sourceuri_term = chado_get_semweb_term('analysis', 'sourceuri');
  14. $content = 'The data source is not provided.';
  15. if ($items[0]['value']) {
  16. $content = "<dl class=\"tripal-dl\">";
  17. if (!empty($items[0]['value'][$sourcename_term])) {
  18. $content .= "<dt>Source Name</dt><dd>: " . $items[0]['value'][$sourcename_term] . " </dd>";
  19. }
  20. if (!empty($items[0]['value'][$sourceversion_term])) {
  21. $content .= "<dt>Source Version</dt><dd>: " . $items[0]['value'][$sourceversion_term] . " </dd>";
  22. }
  23. if (!empty($items[0]['value'][$sourceuri_term])) {
  24. $content .= "<dt>Source URI</dt><dd>: " . l($items[0]['value'][$sourceuri_term], $items[0]['value'][$sourceuri_term], array('attributes' => array('target' => '_blank'))) . " </dd>";
  25. }
  26. $content .= "</dl>";
  27. }
  28. $element[0] = array(
  29. // We create a render array to produce the desired markup,
  30. '#type' => 'markup',
  31. '#markup' => $content,
  32. );
  33. }
  34. }