views_handler_field_markup.inc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_field_markup.
  5. */
  6. /**
  7. * A handler to run a field through check_markup, using a companion
  8. * format field.
  9. *
  10. * - format: (REQUIRED) Either a string format id to use for this field or an
  11. * array('field' => {$field}) where $field is the field in this table used to
  12. * control the format such as the 'format' field in the node, which goes with
  13. * the 'body' field.
  14. *
  15. * @ingroup views_field_handlers
  16. */
  17. class views_handler_field_markup extends views_handler_field {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function construct() {
  22. parent::construct();
  23. $this->format = $this->definition['format'];
  24. $this->additional_fields = array();
  25. if (is_array($this->format)) {
  26. $this->additional_fields['format'] = $this->format;
  27. }
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function render($values) {
  33. $value = $this->get_value($values);
  34. if (is_array($this->format)) {
  35. $format = $this->get_value($values, 'format');
  36. }
  37. else {
  38. $format = $this->format;
  39. }
  40. if ($value) {
  41. $value = str_replace('<!--break-->', '', $value);
  42. return check_markup($value, $format, '');
  43. }
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
  49. if ($inline) {
  50. return 'span';
  51. }
  52. if (isset($this->definition['element type'])) {
  53. return $this->definition['element type'];
  54. }
  55. return 'div';
  56. }
  57. }