data__protein_sequence_formatter.inc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. class data__protein_sequence_formatter extends TripalFieldFormatter {
  3. // The default lable for this field.
  4. public static $label = 'Protein Sequence';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = array('data__protein_sequence');
  7. // The list of default settings for this formatter.
  8. public static $settings = array();
  9. /**
  10. *
  11. * @param unknown $element
  12. * @param unknown $entity_type
  13. * @param unknown $entity
  14. * @param unknown $langcode
  15. * @param unknown $items
  16. * @param unknown $display
  17. */
  18. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  19. $element[0] = array(
  20. // We create a render array to produce the desired markup,
  21. '#type' => 'markup',
  22. '#markup' => '',
  23. );
  24. $num_bases = 50;
  25. foreach ($items as $delta => $item) {
  26. // If there are no residues then skip this one.
  27. if (!is_array($item['value']) or !array_key_exists('residues', $item['value'])) {
  28. continue;
  29. }
  30. $residues = $item['value']['residues'];
  31. $content .= '<pre class="residues-formatter">';
  32. $content .= '>' . $defline . "<br>";
  33. $content .= wordwrap($residues, $num_bases, "<br>", TRUE);
  34. $content .= '</pre>';
  35. $element[$delta] = array(
  36. // We create a render array to produce the desired markup,
  37. '#type' => 'markup',
  38. '#markup' => $content,
  39. );
  40. }
  41. }
  42. }