Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / views / tests / modules / views_test_data / src / Plugin / views / style / StyleTest.php
1 <?php
2
3 namespace Drupal\views_test_data\Plugin\views\style;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\Plugin\views\style\StylePluginBase;
7
8 /**
9  * Provides a general test style plugin.
10  *
11  * @ingroup views_style_plugins
12  *
13  * @ViewsStyle(
14  *   id = "test_style",
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"}
20  * )
21  */
22 class StyleTest extends StylePluginBase {
23
24   /**
25    * A string which will be output when the view is rendered.
26    *
27    * @var string
28    */
29   public $output;
30
31   /**
32    * {@inheritdoc}
33    */
34   protected $usesRowPlugin = TRUE;
35
36   /**
37    * {@inheritdoc}
38    */
39   protected function defineOptions() {
40     $options = parent::defineOptions();
41     $options['test_option'] = ['default' => ''];
42
43     return $options;
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function buildOptionsForm(&$form, FormStateInterface $form_state) {
50     parent::buildOptionsForm($form, $form_state);
51
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'],
57     ];
58   }
59
60   /**
61    * Sets the usesRowPlugin property.
62    *
63    * @param bool $status
64    *   TRUE if this style plugin should use rows.
65    */
66   public function setUsesRowPlugin($status) {
67     $this->usesRowPlugin = $status;
68   }
69
70   /**
71    * Sets the output property.
72    *
73    * @param string $output
74    *   The string to output by this plugin.
75    */
76   public function setOutput($output) {
77     $this->output = $output;
78   }
79
80   /**
81    * Returns the output property.
82    *
83    * @return string
84    */
85   public function getOutput() {
86     return $this->output;
87   }
88
89   /**
90    * {@inheritdoc}
91    */
92   public function render() {
93     $output = '';
94     if (!$this->usesRowPlugin()) {
95       $output = $this->getOutput();
96     }
97     else {
98       foreach ($this->view->result as $index => $row) {
99         $this->view->row_index = $index;
100         $output .= $this->view->rowPlugin->render($row) . "\n";
101       }
102     }
103
104     return $output;
105   }
106
107   /**
108    * {@inheritdoc}
109    */
110   public function calculateDependencies() {
111     return [
112       'content' => ['StyleTest'],
113     ];
114   }
115
116 }