Markup.php 1.51 KB
Newer Older
merlinofchaos's avatar
merlinofchaos committed
1 2 3 4
<?php

/**
 * @file
5
 * Definition of Drupal\views\Plugin\views\field\Markup.
merlinofchaos's avatar
merlinofchaos committed
6 7
 */

8
namespace Drupal\views\Plugin\views\field;
9

dawehner's avatar
dawehner committed
10 11
use Drupal\Core\Annotation\Plugin;

merlinofchaos's avatar
merlinofchaos committed
12 13 14 15 16 17 18 19 20 21
/**
 * A handler to run a field through check_markup, using a companion
 * format field.
 *
 * - format: (REQUIRED) Either a string format id to use for this field or an
 *           array('field' => {$field}) where $field is the field in this table
 *           used to control the format such as the 'format' field in the node,
 *           which goes with the 'body' field.
 *
 * @ingroup views_field_handlers
22 23
 *
 * @Plugin(
aspilicious's avatar
aspilicious committed
24
 *   id = "markup"
dawehner's avatar
dawehner committed
25 26
 * )
 */
27
class Markup extends FieldPluginBase {
28

29 30
  public function init(&$view, &$options) {
    parent::init($view, $options);
merlinofchaos's avatar
merlinofchaos committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

    $this->format = $this->definition['format'];

    $this->additional_fields = array();
    if (is_array($this->format)) {
      $this->additional_fields['format'] = $this->format;
    }
  }

  function render($values) {
    $value = $this->get_value($values);
    if (is_array($this->format)) {
      $format = $this->get_value($values, 'format');
    }
    else {
      $format = $this->format;
    }
    if ($value) {
      $value = str_replace('<!--break-->', '', $value);
      return check_markup($value, $format, '');
    }
  }

  function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
    if ($inline) {
      return 'span';
    }

    if (isset($this->definition['element type'])) {
      return $this->definition['element type'];
    }

    return 'div';
  }
65

merlinofchaos's avatar
merlinofchaos committed
66
}