Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / views / src / Plugin / views / field / Markup.php
1 <?php
2
3 namespace Drupal\views\Plugin\views\field;
4
5 use Drupal\views\Plugin\views\display\DisplayPluginBase;
6 use Drupal\views\ResultRow;
7 use Drupal\views\ViewExecutable;
8
9 /**
10  * A handler to run a field through check_markup, using a companion
11  * format field.
12  *
13  * - format: (REQUIRED) Either a string format id to use for this field or an
14  *           array('field' => {$field}) where $field is the field in this table
15  *           used to control the format such as the 'format' field in the node,
16  *           which goes with the 'body' field.
17  *
18  * @ingroup views_field_handlers
19  *
20  * @ViewsField("markup")
21  */
22 class Markup extends FieldPluginBase {
23
24   /**
25    * {@inheritdoc}
26    */
27   public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
28     parent::init($view, $display, $options);
29
30     $this->format = $this->definition['format'];
31
32     $this->additional_fields = [];
33     if (is_array($this->format)) {
34       $this->additional_fields['format'] = $this->format;
35     }
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public function render(ResultRow $values) {
42     $value = $this->getValue($values);
43     if (is_array($this->format)) {
44       $format = $this->getValue($values, 'format');
45     }
46     else {
47       $format = $this->format;
48     }
49     if ($value) {
50       $value = str_replace('<!--break-->', '', $value);
51       return check_markup($value, $format);
52     }
53   }
54
55   /**
56    * {@inheritdoc}
57    */
58   public function elementType($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
59     if ($inline) {
60       return 'span';
61     }
62
63     if (isset($this->definition['element type'])) {
64       return $this->definition['element type'];
65     }
66
67     return 'div';
68   }
69
70 }