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.
32 * Can the style plugin use row plugins.
36 protected $usesRowPlugin = TRUE;
41 protected function defineOptions() {
42 $options = parent::defineOptions();
43 $options['test_option'] = ['default' => ''];
51 public function buildOptionsForm(&$form, FormStateInterface $form_state) {
52 parent::buildOptionsForm($form, $form_state);
54 $form['test_option'] = [
55 '#title' => $this->t('Test option'),
56 '#type' => 'textfield',
57 '#description' => $this->t('This is a textfield for test_option.'),
58 '#default_value' => $this->options['test_option'],
63 * Sets the usesRowPlugin property.
66 * TRUE if this style plugin should use rows.
68 public function setUsesRowPlugin($status) {
69 $this->usesRowPlugin = $status;
73 * Sets the output property.
75 * @param string $output
76 * The string to output by this plugin.
78 public function setOutput($output) {
79 $this->output = $output;
83 * Returns the output property.
87 public function getOutput() {
94 public function render() {
96 if (!$this->usesRowPlugin()) {
97 $output = $this->getOutput();
100 foreach ($this->view->result as $index => $row) {
101 $this->view->row_index = $index;
102 $output .= $this->view->rowPlugin->render($row) . "\n";
112 public function calculateDependencies() {
114 'content' => ['StyleTest'],