Version 1
[yaffs-website] / web / core / modules / views / src / Plugin / views / area / Text.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")
13  */
14 class Text extends TokenizeAreaPluginBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   protected function defineOptions() {
20     $options = parent::defineOptions();
21     $options['content'] = [
22       'contains' => [
23         'value' => ['default' => ''],
24         'format' => ['default' => NULL],
25       ],
26     ];
27     return $options;
28   }
29
30   /**
31    * {@inheritdoc}
32    */
33   public function buildOptionsForm(&$form, FormStateInterface $form_state) {
34     parent::buildOptionsForm($form, $form_state);
35
36     $form['content'] = [
37       '#title' => $this->t('Content'),
38       '#type' => 'text_format',
39       '#default_value' => $this->options['content']['value'],
40       '#rows' => 6,
41       '#format' => isset($this->options['content']['format']) ? $this->options['content']['format'] : filter_default_format(),
42       '#editor' => FALSE,
43     ];
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function preQuery() {
50     $content = $this->options['content']['value'];
51     // Check for tokens that require a total row count.
52     if (strpos($content, '[view:page-count]') !== FALSE || strpos($content, '[view:total-rows]') !== FALSE) {
53       $this->view->get_total_rows = TRUE;
54     }
55   }
56
57   /**
58    * {@inheritdoc}
59    */
60   public function render($empty = FALSE) {
61     $format = isset($this->options['content']['format']) ? $this->options['content']['format'] : filter_default_format();
62     if (!$empty || !empty($this->options['empty'])) {
63       return [
64         '#type' => 'processed_text',
65         '#text' => $this->tokenizeValue($this->options['content']['value']),
66         '#format' => $format,
67       ];
68     }
69
70     return [];
71   }
72
73 }