3 namespace Drupal\views\Plugin\views\area;
5 use Drupal\Core\Form\FormStateInterface;
8 * Views area title override handler.
10 * @ingroup views_area_handlers
14 class Title extends AreaPluginBase {
19 protected function defineOptions() {
20 $options = parent::defineOptions();
21 $options['title'] = ['default' => ''];
28 public function buildOptionsForm(&$form, FormStateInterface $form_state) {
29 parent::buildOptionsForm($form, $form_state);
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.'),
38 // Don't use the AreaPluginBase tokenForm method, we don't want row tokens.
39 $this->globalTokenForm($form, $form_state);
45 public function preRender(array $results) {
46 parent::preRender($results);
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'));
58 public function render($empty = FALSE) {
59 // Do nothing for this handler by returning an empty render array.