class StyleTest

Same name in this branch
  1. 9 core/modules/ckeditor5/tests/src/FunctionalJavascript/StyleTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\StyleTest
  2. 9 core/modules/views/tests/src/Kernel/Plugin/StyleTest.php \Drupal\Tests\views\Kernel\Plugin\StyleTest
Same name and namespace in other branches
  1. 11.x core/modules/ckeditor5/tests/src/FunctionalJavascript/StyleTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\StyleTest
  2. 11.x core/modules/views/tests/src/Kernel/Plugin/StyleTest.php \Drupal\Tests\views\Kernel\Plugin\StyleTest
  3. 11.x core/modules/views/tests/modules/views_test_data/src/Plugin/views/style/StyleTest.php \Drupal\views_test_data\Plugin\views\style\StyleTest

Provides a general test style plugin.

Plugin annotation


@ViewsStyle(
  id = "test_style",
  title = @Translation("Test style plugin"),
  help = @Translation("Provides a generic style test plugin."),
  theme = "views_view_style_test",
  register_theme = FALSE,
  display_types = {"normal", "test"}
)

Hierarchy

Expanded class hierarchy of StyleTest

Related topics

1 file declares its use of StyleTest
StyleTest.php in core/modules/views/tests/src/Kernel/Plugin/StyleTest.php
3 string references to 'StyleTest'
StyleTest::calculateDependencies in core/modules/views/tests/modules/views_test_data/src/Plugin/views/style/StyleTest.php
ViewEntityDependenciesTest::testGetDependencies in core/modules/views/tests/src/Kernel/Entity/ViewEntityDependenciesTest.php
Tests the getDependencies method.
views.view.test_plugin_dependencies.yml in core/modules/views/tests/modules/views_test_config/test_views/views.view.test_plugin_dependencies.yml
core/modules/views/tests/modules/views_test_config/test_views/views.view.test_plugin_dependencies.yml

File

core/modules/views/tests/modules/views_test_data/src/Plugin/views/style/StyleTest.php, line 22

Namespace

Drupal\views_test_data\Plugin\views\style
View source
class StyleTest extends StylePluginBase {
  
  /**
   * A string which will be output when the view is rendered.
   *
   * @var string
   */
  public $output;
  
  /**
   * {@inheritdoc}
   */
  protected $usesRowPlugin = TRUE;
  
  /**
   * {@inheritdoc}
   */
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['test_option'] = [
      'default' => '',
    ];
    return $options;
  }
  
  /**
   * {@inheritdoc}
   */
  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'],
    ];
  }
  
  /**
   * Sets the usesRowPlugin property.
   *
   * @param bool $status
   *   TRUE if this style plugin should use rows.
   */
  public function setUsesRowPlugin($status) {
    $this->usesRowPlugin = $status;
  }
  
  /**
   * Sets the output property.
   *
   * @param string $output
   *   The string to output by this plugin.
   */
  public function setOutput($output) {
    $this->output = $output;
  }
  
  /**
   * Returns the output property.
   *
   * @return string
   */
  public function getOutput() {
    return $this->output;
  }
  
  /**
   * {@inheritdoc}
   */
  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;
  }
  
  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    return [
      'content' => [
        'StyleTest',
      ],
    ];
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.