data__sequence_formatter.inc 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. class data__sequence_formatter extends ChadoFieldFormatter {
  3. // The default lable for this field.
  4. public static $default_label = 'Sequence';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = array('data__sequence');
  7. /**
  8. * @see TripalFieldFormatter::view()
  9. */
  10. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  11. // If there are no items, we don't want to return any markup.
  12. if (count($items) == 0 or (count($items) == 1 and empty($items[0]['value']))) {
  13. $element[0] = array(
  14. '#type' => 'markup',
  15. '#markup' => 'No sequence is available.',
  16. );
  17. return;
  18. }
  19. $num_bases = 50;
  20. $content = '<pre class="residues-formatter">';
  21. $content .= wordwrap($items[0]['value'], $num_bases, "<br>", TRUE);
  22. $content .= '</pre>';
  23. $element[0] = array(
  24. // We create a render array to produce the desired markup,
  25. '#type' => 'markup',
  26. '#markup' => $content,
  27. );
  28. }
  29. }