schema__publication_formatter.inc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 = 'There are no publications.';
  33. if (count($list_items) > 1) {
  34. $list = array(
  35. 'title' => '',
  36. 'items' => $list_items,
  37. 'type' => 'ol',
  38. 'attributes' => array(),
  39. );
  40. $list = theme_item_list($list);
  41. }
  42. $element[0] = array(
  43. '#type' => 'markup',
  44. '#markup' => $list,
  45. );
  46. }
  47. }