data__sequence_formatter.inc 1021 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. class data__sequence_formatter extends ChadoFieldFormatter {
  3. // The default label 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 = ['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] = [
  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] = [
  24. // We create a render array to produce the desired markup,
  25. '#type' => 'markup',
  26. '#markup' => $content,
  27. ];
  28. }
  29. }