DisplayExtenderTest.php 3.21 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
<?php

/**
 * @file
 * Definition of Drupal\views_test_data\Plugin\views\display_extender\DisplayExtenderTest.
 */

namespace Drupal\views_test_data\Plugin\views\display_extender;

use Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase;
11
use Drupal\Component\Annotation\Plugin;
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use Drupal\Core\Annotation\Translation;

/**
 * Defines a display extender test plugin.
 *
 * @Plugin(
 *   id = "display_extender_test",
 *   title = @Translation("Display extender test")
 * )
 */
class DisplayExtenderTest extends DisplayExtenderPluginBase {

  /**
   * Stores some state booleans to be sure a certain method got called.
   *
   * @var array
   */
  public $testState;

  /**
   * Overrides Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase::defineOptionsAlter().
   */
  public function defineOptionsAlter(&$options) {
    $options['test_extender_test_option'] = array('default' => '');

    return $options;
  }

  /**
   * Overrides Drupal\views\Plugin\views\display\DisplayPluginBase::optionsSummary().
   */
  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),
    );
  }

  /**
   * Overrides Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase::buildOptionsForm().
   */
  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'),
        );
    }
  }

  /**
   * Overrides Drupal\views\Plugin\views\display\DisplayExtenderPluginBase::submitOptionsForm().
   */
  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;
    }
  }

  /**
   * Overrides Drupal\views\Plugin\views\display\DisplayExtenderPluginBase::defaultableSections().
   */
  public function defaultableSections(&$sections, $section = NULL) {
    $sections['test_extender_test_option'] = array('test_extender_test_option');
  }

  /**
   * Overrides Drupal\views\Plugin\views\display\DisplayExtenderPluginBase::query().
   */
  public function query() {
    $this->testState['query'] = TRUE;
  }

  /**
105
   * Overrides Drupal\views\Plugin\views\display\DisplayExtenderPluginBase::preExecute().
106
   */
107
108
  public function preExecute() {
    $this->testState['preExecute'] = TRUE;
109
110
111
  }

}