schema__publication_formatter.inc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. $title = isset($item['value']['TPUB:0000039']) ? $item['value']['TPUB:0000039'] : '';
  22. $citation = isset($item['value']['TPUB:0000003']) ? $item['value']['TPUB:0000003'] : '';
  23. $entity = array_key_exists('entity', $item['value']) ? $item['value']['entity'] : '';
  24. if ($entity) {
  25. list($entity_type, $entity_id) = explode(':', $entity);
  26. $new_title = l($title, 'bio_data/' . $entity_id);
  27. // If a title has parens we need to escape them for the
  28. // regular expression to work.
  29. $title = preg_replace('/\(/', '\(', $title);
  30. $title = preg_replace('/\)/', '\)', $title);
  31. $citation = preg_replace("/$title/", $new_title, $citation);
  32. }
  33. $list_items[] = $citation;
  34. }
  35. krsort($list_items, SORT_NUMERIC);
  36. if (count($list_items) == 0) {
  37. $list = 'There are no publications.';
  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. }