Version 1
[yaffs-website] / web / core / modules / views / src / Plugin / views / area / TextCustom.php
1 <?php
2
3 namespace Drupal\views\Plugin\views\area;
4
5 use Drupal\Core\Form\FormStateInterface;
6
7 /**
8  * Views area text handler.
9  *
10  * @ingroup views_area_handlers
11  *
12  * @ViewsArea("text_custom")
13  */
14 class TextCustom extends TokenizeAreaPluginBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   protected function defineOptions() {
20     $options = parent::defineOptions();
21     $options['content'] = ['default' => ''];
22     return $options;
23   }
24
25   /**
26    * {@inheritdoc}
27    */
28   public function buildOptionsForm(&$form, FormStateInterface $form_state) {
29     parent::buildOptionsForm($form, $form_state);
30
31     $form['content'] = [
32       '#title' => $this->t('Content'),
33       '#type' => 'textarea',
34       '#default_value' => $this->options['content'],
35       '#rows' => 6,
36     ];
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public function render($empty = FALSE) {
43     if (!$empty || !empty($this->options['empty'])) {
44       return [
45         '#markup' => $this->renderTextarea($this->options['content']),
46       ];
47     }
48
49     return [];
50   }
51
52   /**
53    * Render a text area with \Drupal\Component\Utility\Xss::filterAdmin().
54    */
55   public function renderTextarea($value) {
56     if ($value) {
57       return $this->sanitizeValue($this->tokenizeValue($value), 'xss_admin');
58     }
59   }
60
61 }