3 namespace Drupal\views_test_data\Plugin\views\style;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\Plugin\views\style\StylePluginBase;
9 * Provides a general test style plugin.
11 * @ingroup views_style_plugins
15 * title = @Translation("Test style plugin"),
16 * help = @Translation("Provides a generic style test plugin."),
17 * theme = "views_view_style_test",
18 * register_theme = FALSE,
19 * display_types = {"normal", "test"}
22 class StyleTest extends StylePluginBase {
25 * A string which will be output when the view is rendered.
34 protected $usesRowPlugin = TRUE;
39 protected function defineOptions() {
40 $options = parent::defineOptions();
41 $options['test_option'] = ['default' => ''];
49 public function buildOptionsForm(&$form, FormStateInterface $form_state) {
50 parent::buildOptionsForm($form, $form_state);
52 $form['test_option'] = [
53 '#title' => $this->t('Test option'),
54 '#type' => 'textfield',
55 '#description' => $this->t('This is a textfield for test_option.'),
56 '#default_value' => $this->options['test_option'],
61 * Sets the usesRowPlugin property.
64 * TRUE if this style plugin should use rows.
66 public function setUsesRowPlugin($status) {
67 $this->usesRowPlugin = $status;
71 * Sets the output property.
73 * @param string $output
74 * The string to output by this plugin.
76 public function setOutput($output) {
77 $this->output = $output;
81 * Returns the output property.
85 public function getOutput() {
92 public function render() {
94 if (!$this->usesRowPlugin()) {
95 $output = $this->getOutput();
98 foreach ($this->view->result as $index => $row) {
99 $this->view->row_index = $index;
100 $output .= $this->view->rowPlugin->render($row) . "\n";
110 public function calculateDependencies() {
112 'content' => ['StyleTest'],