schema__publication_formatter.inc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. class schema__publication_formatter extends ChadoFieldFormatter {
  3. // The default lable for this field.
  4. public static $default_label = 'Publication';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = array('schema__publication');
  7. /**
  8. *
  9. * @see TripalFieldFormatter::view()
  10. */
  11. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  12. $list_items = array();
  13. $chado_table = $this->instance['settings']['chado_table'];
  14. // If there are no items, we don't want to return any markup.
  15. if (empty($items)) {
  16. return;
  17. }
  18. foreach ($items as $delta => $item) {
  19. if(empty($item['value'])){
  20. continue;
  21. }
  22. $title = isset($item['value']['TPUB:0000039']) ? $item['value']['TPUB:0000039'] : '';
  23. $citation = isset($item['value']['TPUB:0000003']) ? $item['value']['TPUB:0000003'] : '';
  24. $entity = (is_array($item['value']) && array_key_exists('entity', $item['value'])) ? $item['value']['entity'] : '';
  25. if ($entity) {
  26. list($entity_type, $entity_id) = explode(':', $entity);
  27. $new_title = l($title, 'bio_data/' . $entity_id);
  28. // Escape anything that isn't alphanumeric
  29. $title = preg_replace('/([^\w])/', '\\\\$1', $title);
  30. $citation = preg_replace("/$title/", $new_title, $citation);
  31. }
  32. $list_items[] = $citation;
  33. }
  34. $list = '';
  35. krsort($list_items, SORT_NUMERIC);
  36. if (count($list_items) == 0) {
  37. $list = 'There are no publications associated with this record.';
  38. }
  39. if (count($list_items) == 1) {
  40. $list = $list_items[0];
  41. }
  42. if (count($list_items) > 1) {
  43. $list = array(
  44. 'title' => '',
  45. 'items' => $list_items,
  46. 'type' => 'ol',
  47. 'attributes' => array(),
  48. );
  49. $list = theme_item_list($list);
  50. }
  51. $element[0] = array(
  52. '#type' => 'markup',
  53. '#markup' => $list,
  54. );
  55. }
  56. }