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. // 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. $title = isset($item['value']['TPUB:0000039']) ? $item['value']['TPUB:0000039'] : '';
  20. $citation = isset($item['value']['TPUB:0000003']) ? $item['value']['TPUB:0000003'] : '';
  21. $entity = (is_array($item['value']) && array_key_exists('entity', $item['value'])) ? $item['value']['entity'] : '';
  22. if ($entity) {
  23. list($entity_type, $entity_id) = explode(':', $entity);
  24. $new_title = l($title, 'bio_data/' . $entity_id);
  25. // Escape anything that isn't alphanumeric
  26. $title = preg_replace('/([^\w])/', '\\\\$1', $title);
  27. $citation = preg_replace("/$title/", $new_title, $citation);
  28. }
  29. $list_items[] = $citation;
  30. }
  31. $list = '';
  32. krsort($list_items, SORT_NUMERIC);
  33. if (count($list_items) == 0) {
  34. $list = 'There are no publications associated with this record.';
  35. }
  36. if (count($list_items) == 1) {
  37. $list = $list_items[0];
  38. }
  39. if (count($list_items) > 1) {
  40. $list = array(
  41. 'title' => '',
  42. 'items' => $list_items,
  43. 'type' => 'ol',
  44. 'attributes' => array(),
  45. );
  46. $list = theme_item_list($list);
  47. }
  48. $element[0] = array(
  49. '#type' => 'markup',
  50. '#markup' => $list,
  51. );
  52. }
  53. }