schema__publication_formatter.inc 1.9 KB

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