TextCustom.php 1.64 KB
Newer Older
1
2
3
4
5
6
7
8
9
<?php

/**
 * @file
 * Definition of Drupal\views\Plugin\views\area\TextCustom.
 */

namespace Drupal\views\Plugin\views\area;

10
use Drupal\Component\Annotation\PluginID;
11
12
13
14
15

/**
 * Views area text handler.
 *
 * @ingroup views_area_handlers
16
 *
17
 * @PluginID("text_custom")
18
 */
19
class TextCustom extends AreaPluginBase {
20

21
22
  protected function defineOptions() {
    $options = parent::defineOptions();
23
24
    $options['content'] = array('default' => '', 'translatable' => TRUE);
    $options['tokenize'] = array('default' => FALSE, 'bool' => TRUE);
25
26
27
    return $options;
  }

28
29
  public function buildOptionsForm(&$form, &$form_state) {
    parent::buildOptionsForm($form, $form_state);
30

31
32
33
34
35
36
37
38
    $form['content'] = array(
      '#type' => 'textarea',
      '#default_value' => $this->options['content'],
      '#rows' => 6,
    );

    // Add tokenization form elements.
    $this->tokenForm($form, $form_state);
39
40
  }

41
42
  // Empty, so we don't inherit submitOptionsForm from the parent.
  public function submitOptionsForm(&$form, &$form_state) {
43
44
  }

45
46
47
  /**
   * Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render().
   */
48
49
  function render($empty = FALSE) {
    if (!$empty || !empty($this->options['empty'])) {
50
      return array(
51
        '#markup' => $this->renderTextarea($this->options['content']),
52
      );
53
54
    }

55
    return array();
56
57
58
59
60
  }

  /**
   * Render a text area with filter_xss_admin.
   */
61
  public function renderTextarea($value) {
62
63
    if ($value) {
      if ($this->options['tokenize']) {
64
        $value = $this->view->style_plugin->tokenizeValue($value, 0);
65
      }
66
      return $this->sanitizeValue($this->globalTokenReplace($value), 'xss_admin');
67
68
69
70
    }
  }

}