schema__alternate_name_formatter.inc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. class schema__alternate_name_formatter extends TripalFieldFormatter {
  3. // The default lable for this field.
  4. public static $label = 'Synonyms';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = array('schema__alternate_name');
  7. // The list of default settings for this formatter.
  8. public static $settings = array();
  9. /**
  10. *
  11. * @see TripalFieldFormatter::settingsForm()
  12. */
  13. public function settingsForm($view_mode, $form, &$form_state) {
  14. }
  15. /**
  16. *
  17. * @see TripalFieldFormatter::view()
  18. */
  19. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  20. $chado_table = $this->field['settings']['chado_table'];
  21. foreach ($items as $delta => $item) {
  22. if (array_key_exists('chado-' . $chado_table . '__synonym_id', $item) and
  23. $item['chado-' . $chado_table . '__synonym_id']) {
  24. $synonym = chado_generate_var('synonym', array('synonym_id' => $item['chado-' . $chado_table . '__synonym_id']));
  25. $name = $synonym->name;
  26. if ($synonym->type_id->name != 'exact') {
  27. $name .= ' (<i>' . $synonym->type_id->name . '</i>)';
  28. }
  29. $element[$delta] = array(
  30. '#type' => 'markup',
  31. '#markup' => $name,
  32. );
  33. }
  34. }
  35. }
  36. }