so__cds_formatter.inc 1.3 KB

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