Version 1
[yaffs-website] / web / core / modules / views / src / Plugin / views / area / Title.php
1 <?php
2
3 namespace Drupal\views\Plugin\views\area;
4
5 use Drupal\Core\Form\FormStateInterface;
6
7 /**
8  * Views area title override handler.
9  *
10  * @ingroup views_area_handlers
11  *
12  * @ViewsArea("title")
13  */
14 class Title extends AreaPluginBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   protected function defineOptions() {
20     $options = parent::defineOptions();
21     $options['title'] = ['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['title'] = [
32       '#type' => 'textfield',
33       '#title' => $this->t('Overridden title'),
34       '#default_value' => $this->options['title'],
35       '#description' => $this->t('Override the title of this view when it is empty. The available global tokens below can be used here.'),
36     ];
37
38     // Don't use the AreaPluginBase tokenForm method, we don't want row tokens.
39     $this->globalTokenForm($form, $form_state);
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public function preRender(array $results) {
46     parent::preRender($results);
47
48     // If a title is provided, process it.
49     if (!empty($this->options['title'])) {
50       $value = $this->globalTokenReplace($this->options['title']);
51       $this->view->setTitle($this->sanitizeValue($value, 'xss_admin'));
52     }
53   }
54
55   /**
56    * {@inheritdoc}
57    */
58   public function render($empty = FALSE) {
59     // Do nothing for this handler by returning an empty render array.
60     return [];
61   }
62
63 }