schema__publication_formatter.inc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. $citation = preg_replace("/$title/", $new_title, $citation);
  28. }
  29. $list_items[] = $citation;
  30. }
  31. krsort($list_items, SORT_NUMERIC);
  32. $list = '';
  33. if (count($list_items) > 1) {
  34. $list = array(
  35. 'title' => '',
  36. 'items' => $list_items,
  37. 'type' => 'ol',
  38. 'attributes' => array(),
  39. );
  40. }
  41. if (count($items) > 0) {
  42. $element[0] = array(
  43. '#type' => 'markup',
  44. '#markup' => theme_item_list($list),
  45. );
  46. }
  47. }
  48. }