StyleTest.php in Drupal 10
File
core/modules/views/tests/modules/views_test_data/src/Plugin/views/style/StyleTest.php
View source
<?php
namespace Drupal\views_test_data\Plugin\views\style;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\style\StylePluginBase;
class StyleTest extends StylePluginBase {
public $output;
protected $usesRowPlugin = TRUE;
protected function defineOptions() {
$options = parent::defineOptions();
$options['test_option'] = [
'default' => '',
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['test_option'] = [
'#title' => $this
->t('Test option'),
'#type' => 'textfield',
'#description' => $this
->t('This is a textfield for test_option.'),
'#default_value' => $this->options['test_option'],
];
}
public function setUsesRowPlugin($status) {
$this->usesRowPlugin = $status;
}
public function setOutput($output) {
$this->output = $output;
}
public function getOutput() {
return $this->output;
}
public function render() {
$output = '';
if (!$this
->usesRowPlugin()) {
$output = $this
->getOutput();
}
else {
foreach ($this->view->result as $index => $row) {
$this->view->row_index = $index;
$output .= $this->view->rowPlugin
->render($row) . "\n";
}
}
return $output;
}
public function calculateDependencies() {
return [
'content' => [
'StyleTest',
],
];
}
}