sep__protocol_formatter.inc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @class
  4. * Purpose:
  5. *
  6. * Display:
  7. * Configuration:
  8. */
  9. class sep__protocol_formatter extends ChadoFieldFormatter {
  10. // The default label for this field.
  11. public static $default_label = 'Protocol';
  12. // The list of field types for which this formatter is appropriate.
  13. public static $field_types = ['sep__protocol'];
  14. // The list of default settings for this formatter.
  15. public static $default_settings = [
  16. 'setting1' => 'default_value',
  17. ];
  18. /**
  19. * @see TripalFieldFormatter::settingsForm()
  20. */
  21. public function settingsForm($view_mode, $form, &$form_state) {
  22. }
  23. /**
  24. * @see TripalFieldFormatter::view()
  25. */
  26. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  27. if ($items[0]['value']) {
  28. $protocol_name_term = chado_get_semweb_term('protocol', 'name');
  29. $protocol_type_term = chado_get_semweb_term('protocol', 'type_id');
  30. $protocol_name = $items[0]['value'][$protocol_name_term];
  31. $content = $protocol_name;
  32. if (array_key_exists('entity_id', $items[0]['value'])) {
  33. list($entity_type, $entity_id) = explode(':', $items[0]['value']['entity_id']);
  34. if ($entity_id) {
  35. $content = l($protocol_name, 'bio_data/' . $entity_id);
  36. }
  37. }
  38. //cardinality for this field is 1
  39. $element[0] = [
  40. '#type' => 'markup',
  41. '#markup' => $content,
  42. ];
  43. }
  44. }
  45. /**
  46. * @see TripalFieldFormatter::settingsSummary()
  47. */
  48. public function settingsSummary($view_mode) {
  49. return '';
  50. }
  51. }