Title.php in Drupal 10
File
core/modules/views/src/Plugin/views/area/Title.php
View source
<?php
namespace Drupal\views\Plugin\views\area;
use Drupal\Core\Form\FormStateInterface;
class Title extends AreaPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['title'] = [
'default' => '',
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Overridden title'),
'#default_value' => $this->options['title'],
'#description' => $this
->t('Override the title of this view when it is empty. The available global tokens below can be used here.'),
];
$this
->globalTokenForm($form, $form_state);
}
public function preRender(array $results) {
parent::preRender($results);
if (!empty($this->options['title'])) {
$value = $this
->globalTokenReplace($this->options['title']);
$this->view
->setTitle($this
->sanitizeValue($value, 'xss_admin'));
}
}
public function render($empty = FALSE) {
return [];
}
}
Classes
Name |
Description |
Title |
Views area title override handler. |