DisplayExtenderTest.php in Views (for Drupal 7) 8.3        
                          
                  
                        
  
  
  
File
  tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/display_extender/DisplayExtenderTest.php
  
    View source  
  <?php
namespace Drupal\views_test_data\Plugin\views\display_extender;
use Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
class DisplayExtenderTest extends DisplayExtenderPluginBase {
  
  public $testState;
  
  public function defineOptionsAlter(&$options) {
    $options['test_extender_test_option'] = array(
      'default' => '',
    );
    return $options;
  }
  
  public function optionsSummary(&$categories, &$options) {
    parent::optionsSummary($categories, $options);
    $categories['display_extender_test'] = array(
      'title' => t('Display extender test settings'),
      'column' => 'second',
      'build' => array(
        '#weight' => -100,
      ),
    );
    $test_option = $this->displayHandler
      ->getOption('test_extender_test_option') ?: t('Empty');
    $options['test_extender_test_option'] = array(
      'category' => 'display_extender_test',
      'title' => t('Test option'),
      'value' => views_ui_truncate($test_option, 24),
    );
  }
  
  public function buildOptionsForm(&$form, &$form_state) {
    switch ($form_state['section']) {
      case 'test_extender_test_option':
        $form['#title'] .= t('Test option');
        $form['test_extender_test_option'] = array(
          '#type' => 'textfield',
          '#description' => t('This is a textfield for test_option.'),
          '#default_value' => $this->displayHandler
            ->getOption('test_extender_test_option'),
        );
    }
  }
  
  public function submitOptionsForm(&$form, &$form_state) {
    parent::submitOptionsForm($form, $form_state);
    switch ($form_state['section']) {
      case 'test_extender_test_option':
        $this->displayHandler
          ->setOption('test_extender_test_option', $form_state['values']['test_extender_test_option']);
        break;
    }
  }
  
  public function defaultableSections(&$sections, $section = NULL) {
    $sections['test_extender_test_option'] = array(
      'test_extender_test_option',
    );
  }
  
  public function query() {
    $this->testState['query'] = TRUE;
  }
  
  public function pre_execute() {
    $this->testState['pre_execute'] = TRUE;
  }
}