schema__publication_formatter.inc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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::settingsForm()
  10. */
  11. public function settingsForm($view_mode, $form, &$form_state) {
  12. }
  13. /**
  14. *
  15. * @see TripalFieldFormatter::view()
  16. */
  17. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  18. $list_items = array();
  19. $chado_table = $this->instance['settings']['chado_table'];
  20. foreach ($items as $delta => $item) {
  21. if (empty($item['value'])) {
  22. continue;
  23. }
  24. $title = isset($item['value']['TPUB:0000039']) ? $item['value']['TPUB:0000039'] : '';
  25. $citation = isset($item['value']['TPUB:0000003']) ? $item['value']['TPUB:0000003'] : '';
  26. $entity = array_key_exists('entity', $item['value']) ? $item['value']['entity'] : '';
  27. if ($entity) {
  28. list($entity_type, $entity_id) = explode(':', $entity);
  29. $new_title = l($title, 'bio_data/' . $entity_id);
  30. // If a title has parens we need to escape them for the
  31. // regular expression to work.
  32. $title = preg_replace('/\(/', '\(', $title);
  33. $title = preg_replace('/\)/', '\)', $title);
  34. $citation = preg_replace("/$title/", $new_title, $citation);
  35. }
  36. $list_items[] = $citation;
  37. }
  38. $list = '';
  39. krsort($list_items, SORT_NUMERIC);
  40. if (count($list_items) == 0) {
  41. $list = 'There are no publications associated with this record.';
  42. }
  43. if (count($list_items) == 1) {
  44. $list = $list_items[0];
  45. }
  46. if (count($list_items) > 1) {
  47. $list = array(
  48. 'title' => '',
  49. 'items' => $list_items,
  50. 'type' => 'ol',
  51. 'attributes' => array(),
  52. );
  53. $list = theme_item_list($list);
  54. }
  55. $element[0] = array(
  56. '#type' => 'markup',
  57. '#markup' => $list,
  58. );
  59. }
  60. }