Custom.php in Drupal 10
File
core/modules/views/src/Plugin/views/field/Custom.php
View source
<?php
namespace Drupal\views\Plugin\views\field;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Render\ViewsRenderPipelineMarkup;
use Drupal\views\ResultRow;
class Custom extends FieldPluginBase {
public function usesGroupBy() {
return FALSE;
}
public function query() {
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['alter']['contains']['alter_text'] = [
'default' => TRUE,
];
$options['hide_alter_empty'] = [
'default' => FALSE,
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
unset($form['alter']['alter_text']);
unset($form['alter']['text']['#states']);
unset($form['alter']['help']['#states']);
$form['#pre_render'][] = [
$this,
'preRenderCustomForm',
];
}
public static function trustedCallbacks() {
$callbacks = parent::trustedCallbacks();
$callbacks[] = 'preRenderCustomForm';
return $callbacks;
}
public function render(ResultRow $values) {
return ViewsRenderPipelineMarkup::create(Xss::filterAdmin($this->options['alter']['text']));
}
public function preRenderCustomForm($form) {
$form['text'] = $form['alter']['text'];
$form['help'] = $form['alter']['help'];
unset($form['alter']['text']);
unset($form['alter']['help']);
return $form;
}
}
Classes
Name |
Description |
Custom |
A handler to provide a field that is completely custom by the administrator. |