DisplayPluginBase.php 94.9 KB
Newer Older
merlinofchaos's avatar
merlinofchaos committed
1 2 3 4
<?php

/**
 * @file
5
 * Contains Drupal\views\Plugin\views\display\DisplayPluginBase.
merlinofchaos's avatar
merlinofchaos committed
6 7
 */

8
namespace Drupal\views\Plugin\views\display;
9

10
use Drupal\Component\Utility\String;
11
use Drupal\Core\Language\Language;
12
use Drupal\Core\Theme\Registry;
13
use Drupal\views\Plugin\views\area\AreaPluginBase;
14
use Drupal\views\ViewExecutable;
15
use Drupal\views\Plugin\views\PluginBase;
16
use Drupal\views\Views;
17
use Symfony\Component\DependencyInjection\Exception\RuntimeException as DependencyInjectionRuntimeException;
18

merlinofchaos's avatar
merlinofchaos committed
19 20 21 22 23 24 25
/**
 * @defgroup views_display_plugins Views display plugins
 * @{
 * Display plugins control how Views interact with the rest of Drupal.
 *
 * They can handle creating Views from a Drupal page hook; they can
 * handle creating Views from a Drupal block hook. They can also
26
 * handle creating Views from an external module source.
merlinofchaos's avatar
merlinofchaos committed
27 28 29 30 31 32
 */

/**
 * The default display plugin handler. Display plugins handle options and
 * basic mechanisms for different output methods.
 */
33
abstract class DisplayPluginBase extends PluginBase {
34

merlinofchaos's avatar
merlinofchaos committed
35 36 37
  /**
   * The top object of a view.
   *
38
   * @var \Drupal\views\ViewExecutable
merlinofchaos's avatar
merlinofchaos committed
39 40 41 42 43
   */
  var $view = NULL;

  var $handlers = array();

44 45 46 47 48 49 50
  /**
   * An array of instantiated plugins used in this display.
   *
   * @var array
   */
  protected $plugins = array();

merlinofchaos's avatar
merlinofchaos committed
51 52 53 54 55
  /**
   * Stores all available display extenders.
   */
  var $extender = array();

56 57 58
  /**
   * Overrides Drupal\views\Plugin\Plugin::$usesOptions.
   */
59
  protected $usesOptions = TRUE;
60

61 62 63
  /**
   * Stores the rendered output of the display.
   *
64
   * @see View::render
65 66 67 68
   * @var string
   */
  public $output = NULL;

69 70 71 72 73 74 75
  /**
   * Whether the display allows the use of AJAX or not.
   *
   * @var bool
   */
  protected $usesAJAX = TRUE;

76 77 78 79 80 81 82 83 84 85 86 87 88 89
  /**
   * Whether the display allows the use of a pager or not.
   *
   * @var bool
   */
  protected $usesPager = TRUE;

  /**
   * Whether the display allows the use of a 'more' link or not.
   *
   * @var bool
   */
  protected $usesMore = TRUE;

90 91 92 93 94 95 96 97
  /**
   * Whether the display allows attachments.
   *
   * @var bool
   *   TRUE if the display can use attachments, or FALSE otherwise.
   */
  protected $usesAttachments = FALSE;

98 99 100 101 102 103 104
  /**
   * Whether the display allows area plugins.
   *
   * @var bool
   */
  protected $usesAreas = TRUE;

105 106 107 108 109 110 111
  /**
   * Static cache for unpackOptions, but not if we are in the UI.
   *
   * @var array
   */
  protected static $unpackOptions = array();

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
  /**
   * Constructs a new DisplayPluginBase object.
   *
   * Because DisplayPluginBase::initDisplay() takes the display configuration by
   * reference and handles it differently than usual plugin configuration, pass
   * an empty array of configuration to the parent. This prevents our
   * configuration from being duplicated.
   *
   * @todo Replace DisplayPluginBase::$display with
   *   DisplayPluginBase::$configuration to standardize with other plugins.
   */
  public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
    parent::__construct(array(), $plugin_id, $plugin_definition);
  }

127 128
  public function initDisplay(ViewExecutable $view, array &$display, array &$options = NULL) {
    $this->view = $view;
129
    $this->setOptionDefaults($this->options, $this->defineOptions());
merlinofchaos's avatar
merlinofchaos committed
130 131 132 133
    $this->display = &$display;

    // Load extenders as soon as possible.
    $this->extender = array();
134
    if ($extenders = Views::getEnabledDisplayExtenders()) {
135
      $manager = Views::pluginManager('display_extender');
merlinofchaos's avatar
merlinofchaos committed
136
      foreach ($extenders as $extender) {
137
        if ($plugin = $manager->createInstance($extender)) {
merlinofchaos's avatar
merlinofchaos committed
138 139 140 141 142 143 144 145 146 147
          $plugin->init($this->view, $this);
          $this->extender[$extender] = $plugin;
        }
      }
    }

    // Track changes that the user should know about.
    $changed = FALSE;

    // Make some modifications:
148 149
    if (!isset($options) && isset($display['display_options'])) {
      $options = $display['display_options'];
merlinofchaos's avatar
merlinofchaos committed
150 151
    }

152
    if ($this->isDefaultDisplay() && isset($options['defaults'])) {
merlinofchaos's avatar
merlinofchaos committed
153 154 155
      unset($options['defaults']);
    }

156 157 158 159 160 161
    $skip_cache = \Drupal::config('views.settings')->get('skip_cache');

    if (empty($view->editing) || !$skip_cache) {
      $cid = 'unpackOptions:' . hash('sha256', serialize(array($this->options, $options))) . ':' . \Drupal::languageManager()->getLanguage()->id;
      if (empty(static::$unpackOptions[$cid])) {
        $cache = \Drupal::cache('views_info')->get($cid);
merlinofchaos's avatar
merlinofchaos committed
162 163 164 165
        if (!empty($cache->data)) {
          $this->options = $cache->data;
        }
        else {
166
          $this->unpackOptions($this->options, $options);
167
          \Drupal::cache('views_info')->set($cid, $this->options);
merlinofchaos's avatar
merlinofchaos committed
168
        }
169
        static::$unpackOptions[$cid] = $this->options;
merlinofchaos's avatar
merlinofchaos committed
170 171
      }
      else {
172
        $this->options = static::$unpackOptions[$cid];
merlinofchaos's avatar
merlinofchaos committed
173 174 175
      }
    }
    else {
176
      $this->unpackOptions($this->options, $options);
merlinofchaos's avatar
merlinofchaos committed
177 178
    }

179
    // Convert the field_language and field_language_add_to_query settings.
180 181
    $field_language = $this->getOption('field_language');
    $field_language_add_to_query = $this->getOption('field_language_add_to_query');
182
    if (isset($field_langcode)) {
183 184
      $this->setOption('field_langcode', $field_language);
      $this->setOption('field_langcode_add_to_query', $field_language_add_to_query);
185 186 187
      $changed = TRUE;
    }

merlinofchaos's avatar
merlinofchaos committed
188 189 190 191 192 193
    // Mark the view as changed so the user has a chance to save it.
    if ($changed) {
      $this->view->changed = TRUE;
    }
  }

194
  public function destroy() {
merlinofchaos's avatar
merlinofchaos committed
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
    parent::destroy();

    foreach ($this->handlers as $type => $handlers) {
      foreach ($handlers as $id => $handler) {
        if (is_object($handler)) {
          $this->handlers[$type][$id]->destroy();
        }
      }
    }

    if (isset($this->default_display)) {
      unset($this->default_display);
    }

    foreach ($this->extender as $extender) {
      $extender->destroy();
    }
  }

  /**
   * Determine if this display is the 'default' display which contains
   * fallback settings
   */
218
  public function isDefaultDisplay() { return FALSE; }
merlinofchaos's avatar
merlinofchaos committed
219 220 221 222 223

  /**
   * Determine if this display uses exposed filters, so the view
   * will know whether or not to build them.
   */
224
  public function usesExposed() {
merlinofchaos's avatar
merlinofchaos committed
225 226
    if (!isset($this->has_exposed)) {
      foreach ($this->handlers as $type => $value) {
227
        foreach ($this->view->$type as $handler) {
228
          if ($handler->canExpose() && $handler->isExposed()) {
merlinofchaos's avatar
merlinofchaos committed
229 230 231 232 233 234
            // one is all we need; if we find it, return true.
            $this->has_exposed = TRUE;
            return TRUE;
          }
        }
      }
235
      $pager = $this->getPlugin('pager');
236
      if (isset($pager) && $pager->usesExposed()) {
merlinofchaos's avatar
merlinofchaos committed
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
        $this->has_exposed = TRUE;
        return TRUE;
      }
      $this->has_exposed = FALSE;
    }

    return $this->has_exposed;
  }

  /**
   * Determine if this display should display the exposed
   * filters widgets, so the view will know whether or not
   * to render them.
   *
   * Regardless of what this function
   * returns, exposed filters will not be used nor
253
   * displayed unless usesExposed() returns TRUE.
merlinofchaos's avatar
merlinofchaos committed
254
   */
255
  public function displaysExposed() {
merlinofchaos's avatar
merlinofchaos committed
256 257 258 259
    return TRUE;
  }

  /**
260 261 262 263
   * Whether the display allows the use of AJAX or not.
   *
   * @return bool
   */
264
  public function usesAJAX() {
265 266 267 268 269 270 271
    return $this->usesAJAX;
  }

  /**
   * Whether the display is actually using AJAX or not.
   *
   * @return bool
merlinofchaos's avatar
merlinofchaos committed
272
   */
273
  public function ajaxEnabled() {
274
    if ($this->usesAJAX()) {
275
      return $this->getOption('use_ajax');
merlinofchaos's avatar
merlinofchaos committed
276 277 278 279
    }
    return FALSE;
  }

280 281 282 283 284 285 286 287 288 289
  /**
   * Whether the display is enabled.
   *
   * @return bool
   *   Returns TRUE if the display is marked as enabled, else FALSE.
   */
  public function isEnabled() {
    return (bool) $this->getOption('enabled');
  }

merlinofchaos's avatar
merlinofchaos committed
290
  /**
291 292 293 294 295
   * Whether the display allows the use of a pager or not.
   *
   * @return bool
   */

296
  public function usesPager() {
297 298 299 300 301 302 303
    return $this->usesPager;
  }

  /**
   * Whether the display is using a pager or not.
   *
   * @return bool
merlinofchaos's avatar
merlinofchaos committed
304
   */
305
  public function isPagerEnabled() {
306
    if ($this->usesPager()) {
307
      $pager = $this->getPlugin('pager');
308
      if ($pager) {
309
        return $pager->usePager();
310
      }
merlinofchaos's avatar
merlinofchaos committed
311
    }
312
    return FALSE;
merlinofchaos's avatar
merlinofchaos committed
313 314 315
  }

  /**
316 317 318 319
   * Whether the display allows the use of a 'more' link or not.
   *
   * @return bool
   */
320
  public function usesMore() {
321 322 323 324 325 326 327
    return $this->usesMore;
  }

  /**
   * Whether the display is using the 'more' link or not.
   *
   * @return bool
merlinofchaos's avatar
merlinofchaos committed
328
   */
329
  public function isMoreEnabled() {
330
    if ($this->usesMore()) {
331
      return $this->getOption('use_more');
merlinofchaos's avatar
merlinofchaos committed
332 333 334 335 336 337 338
    }
    return FALSE;
  }

  /**
   * Does the display have groupby enabled?
   */
339 340
  public function useGroupBy() {
    return $this->getOption('group_by');
merlinofchaos's avatar
merlinofchaos committed
341 342 343 344 345
  }

  /**
   * Should the enabled display more link be shown when no more items?
   */
346
  public function useMoreAlways() {
347
    if ($this->usesMore()) {
348
      return $this->getOption('use_more_always');
merlinofchaos's avatar
merlinofchaos committed
349 350 351 352 353 354 355
    }
    return FALSE;
  }

  /**
   * Does the display have custom link text?
   */
356
  public function useMoreText() {
357
    if ($this->usesMore()) {
358
      return $this->getOption('use_more_text');
merlinofchaos's avatar
merlinofchaos committed
359 360 361 362 363
    }
    return FALSE;
  }

  /**
364 365 366
   * Determines whether this display can use attachments.
   *
   * @return bool
merlinofchaos's avatar
merlinofchaos committed
367
   */
368
  public function acceptAttachments() {
369 370 371
    // To be able to accept attachments this display have to be able to use
    // attachments but at the same time, you cannot attach a display to itself.
    if (!$this->usesAttachments() || ($this->definition['id'] == $this->view->current_display)) {
merlinofchaos's avatar
merlinofchaos committed
372 373
      return FALSE;
    }
374

375
    if (!empty($this->view->argument) && $this->getOption('hide_attachment_summary')) {
376
      foreach ($this->view->argument as $argument) {
377
        if ($argument->needsStylePlugin() && empty($argument->argument_validated)) {
merlinofchaos's avatar
merlinofchaos committed
378 379 380 381
          return FALSE;
        }
      }
    }
382

merlinofchaos's avatar
merlinofchaos committed
383 384 385
    return TRUE;
  }

386 387 388 389 390
  /**
   * Returns whether the display can use attachments.
   *
   * @return bool
   */
391
  public function usesAttachments() {
392 393 394
    return $this->usesAttachments;
  }

395 396 397 398 399 400 401 402 403 404
  /**
   * Returns whether the display can use areas.
   *
   * @return bool
   *   TRUE if the display can use areas, or FALSE otherwise.
   */
  public function usesAreas() {
    return $this->usesAreas;
  }

merlinofchaos's avatar
merlinofchaos committed
405 406 407
  /**
   * Allow displays to attach to other views.
   */
408
  public function attachTo(ViewExecutable $view, $display_id) { }
merlinofchaos's avatar
merlinofchaos committed
409 410 411 412 413

  /**
   * Static member function to list which sections are defaultable
   * and what items each section contains.
   */
414
  public function defaultableSections($section = NULL) {
merlinofchaos's avatar
merlinofchaos committed
415
    $sections = array(
416 417
      'access' => array('access'),
      'cache' => array('cache'),
merlinofchaos's avatar
merlinofchaos committed
418 419 420 421
      'title' => array('title'),
      'css_class' => array('css_class'),
      'use_ajax' => array('use_ajax'),
      'hide_attachment_summary' => array('hide_attachment_summary'),
422
      'show_admin_links' => array('show_admin_links'),
merlinofchaos's avatar
merlinofchaos committed
423 424 425
      'group_by' => array('group_by'),
      'query' => array('query'),
      'use_more' => array('use_more', 'use_more_always', 'use_more_text'),
426 427
      'use_more_always' => array('use_more', 'use_more_always', 'use_more_text'),
      'use_more_text' => array('use_more', 'use_more_always', 'use_more_text'),
merlinofchaos's avatar
merlinofchaos committed
428 429 430
      'link_display' => array('link_display', 'link_url'),

      // Force these to cascade properly.
431 432
      'style' => array('style', 'row'),
      'row' => array('style', 'row'),
merlinofchaos's avatar
merlinofchaos committed
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452

      'pager' => array('pager', 'pager_options'),
      'pager_options' => array('pager', 'pager_options'),

      'exposed_form' => array('exposed_form', 'exposed_form_options'),
      'exposed_form_options' => array('exposed_form', 'exposed_form_options'),

      // These guys are special
      'header' => array('header'),
      'footer' => array('footer'),
      'empty' => array('empty'),
      'relationships' => array('relationships'),
      'fields' => array('fields'),
      'sorts' => array('sorts'),
      'arguments' => array('arguments'),
      'filters' => array('filters', 'filter_groups'),
      'filter_groups' => array('filters', 'filter_groups'),
    );

    // If the display cannot use a pager, then we cannot default it.
453
    if (!$this->usesPager()) {
merlinofchaos's avatar
merlinofchaos committed
454 455 456 457 458
      unset($sections['pager']);
      unset($sections['items_per_page']);
    }

    foreach ($this->extender as $extender) {
459
      $extender->defaultableSections($sections, $section);
merlinofchaos's avatar
merlinofchaos committed
460 461 462 463 464 465 466 467 468 469 470 471
    }

    if ($section) {
      if (!empty($sections[$section])) {
        return $sections[$section];
      }
    }
    else {
      return $sections;
    }
  }

472
  protected function defineOptions() {
merlinofchaos's avatar
merlinofchaos committed
473 474 475 476 477 478 479 480 481 482 483 484
    $options = array(
      'defaults' => array(
        'default' => array(
          'access' => TRUE,
          'cache' => TRUE,
          'query' => TRUE,
          'title' => TRUE,
          'css_class' => TRUE,

          'display_description' => FALSE,
          'use_ajax' => TRUE,
          'hide_attachment_summary' => TRUE,
485
          'show_admin_links' => TRUE,
merlinofchaos's avatar
merlinofchaos committed
486 487 488 489 490 491 492
          'pager' => TRUE,
          'use_more' => TRUE,
          'use_more_always' => TRUE,
          'use_more_text' => TRUE,
          'exposed_form' => TRUE,

          'link_display' => TRUE,
493
          'link_url' => TRUE,
merlinofchaos's avatar
merlinofchaos committed
494 495
          'group_by' => TRUE,

496 497
          'style' => TRUE,
          'row' => TRUE,
merlinofchaos's avatar
merlinofchaos committed
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539

          'header' => TRUE,
          'footer' => TRUE,
          'empty' => TRUE,

          'relationships' => TRUE,
          'fields' => TRUE,
          'sorts' => TRUE,
          'arguments' => TRUE,
          'filters' => TRUE,
          'filter_groups' => TRUE,
        ),
      ),

      'title' => array(
        'default' => '',
        'translatable' => TRUE,
      ),
      'enabled' => array(
        'default' => TRUE,
        'translatable' => FALSE,
        'bool' => TRUE,
      ),
      'display_comment' => array(
        'default' => '',
      ),
      'css_class' => array(
        'default' => '',
        'translatable' => FALSE,
      ),
      'display_description' => array(
        'default' => '',
        'translatable' => TRUE,
      ),
      'use_ajax' => array(
        'default' => FALSE,
        'bool' => TRUE,
      ),
      'hide_attachment_summary' => array(
        'default' => FALSE,
        'bool' => TRUE,
      ),
540 541
      'show_admin_links' => array(
        'default' => TRUE,
542 543
        'bool' => TRUE,
      ),
merlinofchaos's avatar
merlinofchaos committed
544 545 546 547 548
      'use_more' => array(
        'default' => FALSE,
        'bool' => TRUE,
      ),
      'use_more_always' => array(
549
        'default' => TRUE,
550
        'bool' => TRUE,
merlinofchaos's avatar
merlinofchaos committed
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
      ),
      'use_more_text' => array(
        'default' => 'more',
        'translatable' => TRUE,
      ),
      'link_display' => array(
        'default' => '',
      ),
      'link_url' => array(
        'default' => '',
      ),
      'group_by' => array(
        'default' => FALSE,
        'bool' => TRUE,
      ),
566
      'field_langcode' => array(
merlinofchaos's avatar
merlinofchaos committed
567 568
        'default' => '***CURRENT_LANGUAGE***',
      ),
569 570 571
      'field_langcode_add_to_query' => array(
        'default' => TRUE,
        'bool' => TRUE,
merlinofchaos's avatar
merlinofchaos committed
572 573 574 575 576 577
      ),

      // These types are all plugins that can have individual settings
      // and therefore need special handling.
      'access' => array(
        'contains' => array(
578
          'type' => array('default' => 'none'),
579 580
          'options' => array('default' => array()),
        ),
581
        'merge_defaults' => array($this, 'mergePlugin'),
merlinofchaos's avatar
merlinofchaos committed
582 583 584
      ),
      'cache' => array(
        'contains' => array(
585
          'type' => array('default' => 'none'),
586 587
          'options' => array('default' => array()),
        ),
588
        'merge_defaults' => array($this, 'mergePlugin'),
merlinofchaos's avatar
merlinofchaos committed
589 590 591
      ),
      'query' => array(
        'contains' => array(
592 593
          'type' => array('default' => 'views_query'),
          'options' => array('default' => array()),
merlinofchaos's avatar
merlinofchaos committed
594
         ),
595
        'merge_defaults' => array($this, 'mergePlugin'),
merlinofchaos's avatar
merlinofchaos committed
596 597 598
      ),
      'exposed_form' => array(
        'contains' => array(
599 600
          'type' => array('default' => 'basic'),
          'options' => array('default' => array()),
merlinofchaos's avatar
merlinofchaos committed
601
         ),
602
        'merge_defaults' => array($this, 'mergePlugin'),
merlinofchaos's avatar
merlinofchaos committed
603 604 605
      ),
      'pager' => array(
        'contains' => array(
606
          'type' => array('default' => 'mini'),
607
          'options' => array('default' => array()),
merlinofchaos's avatar
merlinofchaos committed
608
         ),
609
        'merge_defaults' => array($this, 'mergePlugin'),
merlinofchaos's avatar
merlinofchaos committed
610
      ),
611 612 613 614 615
      'style' => array(
        'contains' => array(
          'type' => array('default' => 'default'),
          'options' => array('default' => array()),
        ),
616
        'merge_defaults' => array($this, 'mergePlugin'),
merlinofchaos's avatar
merlinofchaos committed
617
      ),
618 619 620 621 622
      'row' => array(
        'contains' => array(
          'type' => array('default' => 'fields'),
          'options' => array('default' => array()),
        ),
623
        'merge_defaults' => array($this, 'mergePlugin'),
merlinofchaos's avatar
merlinofchaos committed
624 625 626 627 628 629 630 631
      ),

      'exposed_block' => array(
        'default' => FALSE,
      ),

      'header' => array(
        'default' => array(),
632
        'merge_defaults' => array($this, 'mergeHandler'),
merlinofchaos's avatar
merlinofchaos committed
633 634 635
      ),
      'footer' => array(
        'default' => array(),
636
        'merge_defaults' => array($this, 'mergeHandler'),
merlinofchaos's avatar
merlinofchaos committed
637 638 639
      ),
      'empty' => array(
        'default' => array(),
640
        'merge_defaults' => array($this, 'mergeHandler'),
merlinofchaos's avatar
merlinofchaos committed
641 642 643 644 645 646
      ),

      // We want these to export last.
      // These are the 5 handler types.
      'relationships' => array(
        'default' => array(),
647
        'merge_defaults' => array($this, 'mergeHandler'),
merlinofchaos's avatar
merlinofchaos committed
648 649 650
      ),
      'fields' => array(
        'default' => array(),
651
        'merge_defaults' => array($this, 'mergeHandler'),
merlinofchaos's avatar
merlinofchaos committed
652 653 654
      ),
      'sorts' => array(
        'default' => array(),
655
        'merge_defaults' => array($this, 'mergeHandler'),
merlinofchaos's avatar
merlinofchaos committed
656 657 658
      ),
      'arguments' => array(
        'default' => array(),
659
        'merge_defaults' => array($this, 'mergeHandler'),
merlinofchaos's avatar
merlinofchaos committed
660 661 662 663 664 665 666 667 668 669 670 671
      ),
      'filter_groups' => array(
        'contains' => array(
          'operator' => array('default' => 'AND'),
          'groups' => array('default' => array(1 => 'AND')),
        ),
      ),
      'filters' => array(
        'default' => array(),
      ),
    );

672
    if (!$this->usesPager()) {
merlinofchaos's avatar
merlinofchaos committed
673 674 675 676 677 678 679
      $options['defaults']['default']['use_pager'] = FALSE;
      $options['defaults']['default']['items_per_page'] = FALSE;
      $options['defaults']['default']['offset'] = FALSE;
      $options['defaults']['default']['pager'] = FALSE;
      $options['pager']['contains']['type']['default'] = 'some';
    }

680
    if ($this->isDefaultDisplay()) {
merlinofchaos's avatar
merlinofchaos committed
681 682 683 684
      unset($options['defaults']);
    }

    foreach ($this->extender as $extender) {
685
      $extender->defineOptionsAlter($options);
merlinofchaos's avatar
merlinofchaos committed
686 687 688 689 690 691 692 693 694 695 696 697 698 699
    }

    return $options;
  }

  /**
   * Check to see if the display has a 'path' field.
   *
   * This is a pure function and not just a setting on the definition
   * because some displays (such as a panel pane) may have a path based
   * upon configuration.
   *
   * By default, displays do not have a path.
   */
700
  public function hasPath() { return FALSE; }
merlinofchaos's avatar
merlinofchaos committed
701 702 703 704 705 706 707 708

  /**
   * Check to see if the display has some need to link to another display.
   *
   * For the most part, displays without a path will use a link display. However,
   * sometimes displays that have a path might also need to link to another display.
   * This is true for feeds.
   */
709
  public function usesLinkDisplay() { return !$this->hasPath(); }
merlinofchaos's avatar
merlinofchaos committed
710 711 712 713 714 715 716 717 718

  /**
   * Check to see if the display can put the exposed formin a block.
   *
   * By default, displays that do not have a path cannot disconnect
   * the exposed form and put it in a block, because the form has no
   * place to go and Views really wants the forms to go to a specific
   * page.
   */
719
  public function usesExposedFormInBlock() { return $this->hasPath(); }
merlinofchaos's avatar
merlinofchaos committed
720

721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
  /**
   * Find out all displays which are attached to this display.
   *
   * The method is just using the pure storage object to avoid loading of the
   * sub displays which would kill lazy loading.
   */
  public function getAttachedDisplays() {
    $current_display_id = $this->display['id'];
    $attached_displays = array();

    // Go through all displays and search displays which link to this one.
    foreach ($this->view->storage->get('display') as $display_id => $display) {
      if (isset($display['display_options']['displays'])) {
        $displays = $display['display_options']['displays'];
        if (isset($displays[$current_display_id])) {
          $attached_displays[] = $display_id;
        }
      }
    }

    return $attached_displays;
  }

merlinofchaos's avatar
merlinofchaos committed
744 745 746 747
  /**
   * Check to see which display to use when creating links within
   * a view using this display.
   */
748 749
  public function getLinkDisplay() {
    $display_id = $this->getOption('link_display');
merlinofchaos's avatar
merlinofchaos committed
750
    // If unknown, pick the first one.
751
    if (empty($display_id) || !$this->view->displayHandlers->has($display_id)) {
752 753
      foreach ($this->view->displayHandlers as $display_id => $display) {
        if (!empty($display) && $display->hasPath()) {
merlinofchaos's avatar
merlinofchaos committed
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769
          return $display_id;
        }
      }
    }
    else {
      return $display_id;
    }
    // fall-through returns NULL
  }

  /**
   * Return the base path to use for this display.
   *
   * This can be overridden for displays that do strange things
   * with the path.
   */
770 771 772
  public function getPath() {
    if ($this->hasPath()) {
      return $this->getOption('path');
merlinofchaos's avatar
merlinofchaos committed
773 774
    }

775
    $display_id = $this->getLinkDisplay();
776 777
    if ($display_id && $this->view->displayHandlers->has($display_id) && is_object($this->view->displayHandlers->get($display_id))) {
      return $this->view->displayHandlers->get($display_id)->getPath();
merlinofchaos's avatar
merlinofchaos committed
778 779 780
    }
  }

781
  public function getUrl() {
782
    return $this->view->getUrl();
merlinofchaos's avatar
merlinofchaos committed
783 784 785 786 787 788 789 790 791
  }

  /**
   * Determine if a given option is set to use the default display or the
   * current display
   *
   * @return
   *   TRUE for the default display
   */
792 793
  public function isDefaulted($option) {
    return !$this->isDefaultDisplay() && !empty($this->default_display) && !empty($this->options['defaults'][$option]);
merlinofchaos's avatar
merlinofchaos committed
794 795 796 797 798 799
  }

  /**
   * Intelligently get an option either from this display or from the
   * default display, if directed to do so.
   */
800 801 802
  public function getOption($option) {
    if ($this->isDefaulted($option)) {
      return $this->default_display->getOption($option);
merlinofchaos's avatar
merlinofchaos committed
803 804 805 806 807 808 809 810 811
    }

    if (array_key_exists($option, $this->options)) {
      return $this->options[$option];
    }
  }

  /**
   * Determine if the display's style uses fields.
812 813
   *
   * @return bool
merlinofchaos's avatar
merlinofchaos committed
814
   */
815
  public function usesFields() {
816
    return $this->getPlugin('style')->usesFields();
merlinofchaos's avatar
merlinofchaos committed
817 818 819 820 821 822 823 824
  }

  /**
   * Get the instance of a plugin, for example style or row.
   *
   * @param string $type
   *   The type of the plugin.
   *
825
   * @return \Drupal\views\Plugin\views\PluginBase
826 827
   */
  public function getPlugin($type) {
828
    // Look up the plugin name to use for this instance.
829
    $options = $this->getOption($type);
830 831 832 833 834

    // Return now if no options have been loaded.
    if (empty($options) || !isset($options['type'])) {
      return;
    }
merlinofchaos's avatar
merlinofchaos committed
835

836 837
    // Query plugins allow specifying a specific query class per base table.
    if ($type == 'query') {
838
      $views_data = Views::viewsData()->get($this->view->storage->get('base_table'));
839
      $name = isset($views_data['table']['base']['query_id']) ? $views_data['table']['base']['query_id'] : 'views_query';
840
    }
841 842 843
    else {
      $name = $options['type'];
    }
844

845 846
    // Plugin instances are stored on the display for re-use.
    if (!isset($this->plugins[$type][$name])) {
847
      $plugin = Views::pluginManager($type)->createInstance($name);
merlinofchaos's avatar
merlinofchaos committed
848

849 850
      // Initialize the plugin.
      $plugin->init($this->view, $this, $options['options']);
851

852
      $this->plugins[$type][$name] = $plugin;
merlinofchaos's avatar
merlinofchaos committed
853 854
    }

855
    return $this->plugins[$type][$name];
merlinofchaos's avatar
merlinofchaos committed
856 857 858 859 860
  }

  /**
   * Get the handler object for a single handler.
   */
861
  public function &getHandler($type, $id) {
merlinofchaos's avatar
merlinofchaos committed
862
    if (!isset($this->handlers[$type])) {
863
      $this->getHandlers($type);
merlinofchaos's avatar
merlinofchaos committed
864 865 866 867 868 869 870 871 872 873 874 875 876 877
    }

    if (isset($this->handlers[$type][$id])) {
      return $this->handlers[$type][$id];
    }

    // So we can return a reference.
    $null = NULL;
    return $null;
  }

  /**
   * Get a full array of handlers for $type. This caches them.
   */
878
  public function getHandlers($type) {
merlinofchaos's avatar
merlinofchaos committed
879 880
    if (!isset($this->handlers[$type])) {
      $this->handlers[$type] = array();
881
      $types = ViewExecutable::viewsHandlerTypes();
merlinofchaos's avatar
merlinofchaos committed
882 883
      $plural = $types[$type]['plural'];

884
      foreach ($this->getOption($plural) as $id => $info) {
merlinofchaos's avatar
merlinofchaos committed
885 886 887
        // If this is during form submission and there are temporary options
        // which can only appear if the view is in the edit cache, use those
        // options instead. This is used for AJAX multi-step stuff.
888 889 890 891 892 893 894 895 896
        // @todo Remove dependency on Request object
        //   https://drupal.org/node/2059003.
        try {
          $request = \Drupal::request();
          if ($request->request->get('form_id') && isset($this->view->temporary_options[$type][$id])) {
            $info = $this->view->temporary_options[$type][$id];
          }
        }
        catch (DependencyInjectionRuntimeException $e) {
merlinofchaos's avatar
merlinofchaos committed
897 898 899 900 901 902 903 904 905 906
        }

        if ($info['id'] != $id) {
          $info['id'] = $id;
        }

        // If aggregation is on, the group type might override the actual
        // handler that is in use. This piece of code checks that and,
        // if necessary, sets the override handler.
        $override = NULL;
907
        if ($this->useGroupBy() && !empty($info['group_type'])) {
merlinofchaos's avatar
merlinofchaos committed
908
          if (empty($this->view->query)) {
909
            $this->view->initQuery();
merlinofchaos's avatar
merlinofchaos committed
910
          }
911
          $aggregate = $this->view->query->getAggregationInfo();
merlinofchaos's avatar
merlinofchaos committed
912 913 914 915 916 917 918 919 920 921 922 923
          if (!empty($aggregate[$info['group_type']]['handler'][$type])) {
            $override = $aggregate[$info['group_type']]['handler'][$type];
          }
        }

        if (!empty($types[$type]['type'])) {
          $handler_type = $types[$type]['type'];
        }
        else {
          $handler_type = $type;
        }

924
        if ($handler = Views::handlerManager($handler_type)->getHandler($info, $override)) {
merlinofchaos's avatar
merlinofchaos committed
925
          // Special override for area types so they know where they come from.
926 927
          if ($handler instanceof AreaPluginBase) {
            $handler->areaType = $type;
merlinofchaos's avatar
merlinofchaos committed
928 929
          }

930
          $handler->init($this->view, $this, $info);
merlinofchaos's avatar
merlinofchaos committed
931 932 933 934 935 936 937 938 939 940 941 942
          $this->handlers[$type][$id] = &$handler;
        }

        // Prevent reference problems.
        unset($handler);
      }
    }

    return $this->handlers[$type];
  }

  /**
943
   * Retrieves a list of fields for the current display.
944
   *
945 946 947 948
   * This also takes into account any associated relationships, if they exist.
   *
   * @param bool $groupable_only
   *   (optional) TRUE to only return an array of field labels from handlers
949
   *   that support the useStringGroupBy method, defaults to FALSE.
950 951 952
   *
   * @return array
   *   An array of applicable field options, keyed by ID.
merlinofchaos's avatar
merlinofchaos committed
953
   */
954
  public function getFieldLabels($groupable_only = FALSE) {
merlinofchaos's avatar
merlinofchaos committed
955
    $options = array();
956
    foreach ($this->getHandlers('relationship') as $relationship => $handler) {
957
      $relationships[$relationship] = $handler->adminLabel();
merlinofchaos's avatar
merlinofchaos committed
958 959
    }

960
    foreach ($this->getHandlers('field') as $id => $handler) {
961
      if ($groupable_only && !$handler->useStringGroupBy()) {
962 963 964
        // Continue to next handler if it's not groupable.
        continue;
      }
merlinofchaos's avatar
merlinofchaos committed
965 966 967 968
      if ($label = $handler->label()) {
        $options[$id] = $label;
      }
      else {
969
        $options[$id] = $handler->adminLabel();
merlinofchaos's avatar
merlinofchaos committed
970 971 972 973 974 975 976 977 978 979 980 981
      }
      if (!empty($handler->options['relationship']) && !empty($relationships[$handler->options['relationship']])) {
        $options[$id] = '(' . $relationships[$handler->options['relationship']] . ') ' . $options[$id];
      }
    }
    return $options;
  }

  /**
   * Intelligently set an option either from this display or from the
   * default display, if directed to do so.
   */
982 983 984
  public function setOption($option, $value) {
    if ($this->isDefaulted($option)) {
      return $this->default_display->setOption($option, $value);
merlinofchaos's avatar
merlinofchaos committed
985 986 987 988 989
    }

    // Set this in two places: On the handler where we'll notice it
    // but also on the display object so it gets saved. This should
    // only be a temporary fix.
990
    $this->display['display_options'][$option] = $value;
merlinofchaos's avatar
merlinofchaos committed
991 992 993 994 995 996
    return $this->options[$option] = $value;
  }

  /**
   * Set an option and force it to be an override.
   */
997 998 999
  public function overrideOption($option, $value) {
    $this->setOverride($option, FALSE);
    $this->setOption($option, $value);
merlinofchaos's avatar
merlinofchaos committed
1000 1001 1002 1003 1004 1005
  }

  /**
   * Because forms may be split up into sections, this provides
   * an easy URL to exactly the right section. Don't override this.
   */
1006
  public function optionLink($text, $section, $class = '', $title = '') {
merlinofchaos's avatar
merlinofchaos committed
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
    if (!empty($class)) {
      $text = '<span>' . $text . '</span>';
    }

    if (!trim($text)) {
      $text = t('Broken field');
    }

    if (empty($title)) {
      $title = $text;
    }

1019
    return l($text, 'admin/structure/views/nojs/display/' . $this->view->storage->id() . '/' . $this->display['id'] . '/' . $section, array('attributes' => array('class' => 'views-ajax-link ' . $class, 'title' => $title, 'id' => drupal_html_id('views-' . $this->display['id'] . '-' . $section)), 'html' => TRUE));
merlinofchaos's avatar
merlinofchaos committed
1020 1021 1022 1023 1024
  }

  /**
   * Returns to tokens for arguments.
   *
1025
   * This function is similar to views_handler_field::getRenderTokens()
merlinofchaos's avatar
merlinofchaos committed
1026 1027
   * but without fields tokens.
   */
1028
  public function getArgumentsTokens() {
merlinofchaos's avatar
merlinofchaos committed
1029 1030 1031 1032 1033
    $tokens = array();
    if (!empty($this->view->build_info['substitutions'])) {
      $tokens = $this->view->build_info['substitutions'];
    }

1034 1035 1036 1037 1038 1039 1040 1041 1042 1043
    // Add tokens for every argument (contextual filter) and path arg.
    $handlers = count($this->view->display_handler->getHandlers('argument'));
    for ($count = 1; $count <= $handlers; $count++) {
      if (!isset($tokens["%$count"])) {
        $tokens["%$count"] = '';
      }
       // Use strip tags as there should never be HTML in the path.
       // However, we need to preserve special characters like " that
       // were removed by check_plain().
      $tokens["!$count"] = isset($this->view->args[$count - 1]) ? strip_tags(decode_entities($this->view->args[$count - 1])) : '';
merlinofchaos's avatar
merlinofchaos committed
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
    }

    return $tokens;
  }

  /**
   * Provide the default summary for options in the views UI.
   *
   * This output is returned as an array.
   */
1054
  public function optionsSummary(&$categories, &$options) {
merlinofchaos's avatar
merlinofchaos committed
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
    $categories = array(
      'title' => array(
        'title' => t('Title'),
        'column' => 'first',
      ),
      'format' => array(
        'title' => t('Format'),
        'column' => 'first',
      ),
      'filters' => array(
        'title' => t('Filters'),
        'column' => 'first',
      ),
      'fields' => array(
        'title' => t('Fields'),
        'column' => 'first',
      ),
      'pager' => array(
        'title' => t('Pager'),
        'column' => 'second',
      ),
      'exposed' => array(
        'title' => t('Exposed form'),
        'column' => 'third',
        'build' => array(
          '#weight' => 1,
        ),
      ),
      'access' => array(
        'title' => '',
        'column' => 'second',
        'build' => array(
          '#weight' => -5,
        ),
      ),
      'other' => array(
        'title' => t('Other'),
        'column' => 'third',
        'build' => array(
          '#weight' => 2,
        ),
      ),
    );

1099
    if ($this->display['id'] != 'default') {
merlinofchaos's avatar
merlinofchaos committed
1100 1101 1102
      $options['display_id'] = array(
        'category' => 'other',
        'title' => t('Machine Name'),
1103
        'value' => !empty($this->display['new_id']) ? check_plain($this->display['new_id']) : check_plain($this->display['id']),
merlinofchaos's avatar
merlinofchaos committed
1104 1105 1106 1107
        'desc' => t('Change the machine name of this display.'),
      );
    }

1108
    $display_comment = check_plain(drupal_substr($this->getOption('display_comment'), 0, 10));
merlinofchaos's avatar
merlinofchaos committed
1109 1110
    $options['display_comment'] = array(
      'category' => 'other',
1111 1112
      'title' => t('Administrative comment'),
      'value' => !empty($display_comment) ? $display_comment : t('None'),
merlinofchaos's avatar
merlinofchaos committed
1113 1114 1115
      'desc' => t('Comment or document this display.'),
    );

1116
    $title = strip_tags($this->getOption('title'));
merlinofchaos's avatar
merlinofchaos committed
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
    if (!$title) {
      $title = t('None');
    }

    $options['title'] = array(
      'category' => 'title',
      'title' => t('Title'),
      'value' => $title,
      'desc' => t('Change the title that this display will use.'),
    );

1128
    $style_plugin_instance = $this->getPlugin('style');
1129 1130
    $style_summary = empty($style_plugin_instance->definition['title']) ? t('Missing style plugin') : $style_plugin_instance->summaryTitle();
    $style_title = empty($style_plugin_instance->definition['title']) ? t('Missing style plugin') : $style_plugin_instance->pluginTitle();
merlinofchaos's avatar
merlinofchaos committed
1131

1132
    $options['style'] = array(
merlinofchaos's avatar
merlinofchaos committed
1133 1134 1135 1136 1137 1138 1139 1140
      'category' => 'format',
      'title' => t('Format'),
      'value' => $style_title,
      'setting' => $style_summary,
      'desc' => t('Change the way content is formatted.'),
    );

    // This adds a 'Settings' link to the style_options setting if the style has options.
1141
    if ($style_plugin_instance->usesOptions()) {
1142
      $options['style']['links']['style_options'] = t('Change settings for this format');
merlinofchaos's avatar
merlinofchaos committed
1143 1144
    }

1145
    if ($style_plugin_instance->usesRowPlugin()) {
1146 1147 1148
      $row_plugin_instance = $this->getPlugin('row');
      $row_summary = empty($row_plugin_instance->definition['title']) ? t('Missing style plugin') : $row_plugin_instance->summaryTitle();
      $row_title = empty($row_plugin_instance->definition['title']) ? t('Missing style plugin') : $row_plugin_instance->pluginTitle();
merlinofchaos's avatar
merlinofchaos committed
1149

1150
      $options['row'] = array(
merlinofchaos's avatar
merlinofchaos committed
1151 1152 1153 1154 1155 1156 1157
        'category' => 'format',
        'title' => t('Show'),
        'value' => $row_title,
        'setting' => $row_summary,
        'desc' => t('Change the way each row in the view is styled.'),
      );
      // This adds a 'Settings' link to the row_options setting if the row style has options.
1158
      if ($row_plugin_instance->usesOptions()) {
1159
        $options['row']['links']['row_options'] = t('Change settings for this style');
merlinofchaos's avatar
merlinofchaos committed
1160 1161
      }
    }
1162
    if ($this->usesAJAX()) {
merlinofchaos's avatar
merlinofchaos committed
1163 1164 1165
      $options['use_ajax'] = array(
        'category' => 'other',
        'title' => t('Use AJAX'),
1166
        'value' => $this->getOption('use_ajax') ? t('Yes') : t('No'),
merlinofchaos's avatar
merlinofchaos committed
1167 1168 1169
        'desc' => t('Change whether or not this display will use AJAX.'),
      );
    }
1170
    if ($this->usesAttachments()) {
merlinofchaos's avatar
merlinofchaos committed
1171 1172 1173
      $options['hide_attachment_summary'] = array(
        'category' => 'other',
        'title' => t('Hide attachments in summary'),
1174
        'value' => $this->getOption('hide_attachment_summary') ? t('Yes') : t('No'),
merlinofchaos's avatar
merlinofchaos committed
1175 1176 1177
        'desc' => t('Change whether or not to display attachments when displaying a contextual filter summary.'),
      );
    }
1178
    if (!isset($this->definition['contextual links locations']) || !empty($this->definition['contextual links locations'])) {
1179
      $options['show_admin_links'] = array(
1180
        'category' => 'other',
1181 1182
        'title' => t('Contextual links'),
        'value' => $this->getOption('show_admin_links') ? t('Shown') : t('Hidden'),
1183 1184 1185
        'desc' => t('Change whether or not to display contextual links for this view.'),
      );
    }
merlinofchaos's avatar
merlinofchaos committed
1186

1187
    $pager_plugin = $this->getPlugin('pager');
merlinofchaos's avatar
merlinofchaos committed
1188 1189
    if (!$pager_plugin) {
      // default to the no pager plugin.
1190
      $pager_plugin = Views::pluginManager('pager')->createInstance('none');
merlinofchaos's avatar
merlinofchaos committed
1191 1192
    }

1193
    $pager_str = $pager_plugin->summaryTitle();
merlinofchaos's avatar
merlinofchaos committed
1194 1195 1196 1197

    $options['pager'] = array(
      'category' => 'pager',
      'title' => t('Use pager'),
1198
      'value' => $pager_plugin->pluginTitle(),
merlinofchaos's avatar
merlinofchaos committed
1199 1200 1201 1202 1203
      'setting' => $pager_str,
      'desc' => t("Change this display's pager setting."),
    );

    // If pagers aren't allowed, change the text of the item:
1204
    if (!$this->usesPager()) {
merlinofchaos's avatar
merlinofchaos committed
1205 1206 1207
      $options['pager']['title'] = t('Items to display');
    }

1208
    if ($pager_plugin->usesOptions()) {
merlinofchaos's avatar
merlinofchaos committed
1209 1210 1211
      $options['pager']['links']['pager_options'] = t('Change settings for this pager type.');
    }

1212
    if ($this->usesMore()) {
merlinofchaos's avatar
merlinofchaos committed
1213 1214 1215
      $options['use_more'] = array(
        'category' => 'pager',
        'title' => t('More link'),
1216
        'value' => $this->getOption('use_more') ? t('Yes') : t('No'),
merlinofchaos's avatar
merlinofchaos committed
1217 1218 1219 1220
        'desc' => t('Specify whether this display will provide a "more" link.'),
      );
    }

1221
    $this->view->initQuery();
1222
    if ($this->view->query->getAggregationInfo()) {
merlinofchaos's avatar
merlinofchaos committed
1223 1224 1225
      $options['group_by'] = array(
        'category' => 'other',
        'title' => t('Use aggregation'),
1226
        'value' => $this->getOption('group_by') ? t('Yes') : t('No'),
merlinofchaos's avatar
merlinofchaos committed
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
        'desc' => t('Allow grouping and aggregation (calculation) of fields.'),
      );
    }

    $options['query'] = array(
      'category' => 'other',
      'title' => t('Query settings'),
      'value' => t('Settings'),
      'desc' => t('Allow to set some advanced settings for the query plugin'),
    );

    $languages = array(
        '***CURRENT_LANGUAGE***' => t("Current user's language"),
        '***DEFAULT_LANGUAGE***' => t("Default site language"),
1241
        Language::LANGCODE_NOT_SPECIFIED => t('Language neutral'),
merlinofchaos's avatar
merlinofchaos committed
1242
    );
1243
    if (\Drupal::moduleHandler()->moduleExists('language')) {
1244
      $languages = array_merge($languages, language_list());
merlinofchaos's avatar
merlinofchaos committed
1245
    }
1246
    $options['field_langcode'] = array(
merlinofchaos's avatar
merlinofchaos committed
1247 1248
      'category' => 'other',
      'title' => t('Field Language'),
1249
      'value' => $languages[$this->getOption('field_langcode')],
merlinofchaos's avatar
merlinofchaos committed
1250 1251 1252
      'desc' => t('All fields which support translations will be displayed in the selected language.'),
    );

1253
    $access_plugin = $this->getPlugin('access');
merlinofchaos's avatar
merlinofchaos committed
1254 1255
    if (!$access_plugin) {
      // default to the no access control plugin.
1256
      $access_plugin = Views::pluginManager('access')->createInstance('none');
merlinofchaos's avatar
merlinofchaos committed
1257 1258
    }

1259
    $access_str = $access_plugin->summaryTitle();
merlinofchaos's avatar
merlinofchaos committed
1260 1261 1262 1263

    $options['access'] = array(
      'category' => 'access',
      'title' => t('Access'),
1264
      'value' => $access_plugin->pluginTitle(),
merlinofchaos's avatar
merlinofchaos committed
1265 1266 1267 1268
      'setting' => $access_str,
      'desc' => t('Specify access control type for this display.'),
    );

1269
    if ($access_plugin->usesOptions()) {
merlinofchaos's avatar
merlinofchaos committed
1270 1271 1272
      $options['access']['links']['access_options'] = t('Change settings for this access type.');
    }

1273
    $cache_plugin = $this->getPlugin('cache');
merlinofchaos's avatar
merlinofchaos committed
1274 1275
    if (!$cache_plugin) {
      // default to the no cache control plugin.
1276
      $cache_plugin = Views::pluginManager('cache')->createInstance('none');
merlinofchaos's avatar
merlinofchaos committed
1277 1278
    }

1279
    $cache_str = $cache_plugin->summaryTitle();
merlinofchaos's avatar
merlinofchaos committed
1280 1281 1282 1283

    $options['cache'] = array(
      'category' => 'other',
      'title' => t('Caching'),
1284
      'value' => $cache_plugin->pluginTitle(),
merlinofchaos's avatar
merlinofchaos committed
1285 1286 1287 1288
      'setting' => $cache_str,
      'desc' => t('Specify caching type for this display.'),
    );

1289
    if ($cache_plugin->usesOptions()) {
merlinofchaos's avatar
merlinofchaos committed
1290 1291 1292
      $options['cache']['links']['cache_options'] = t('Change settings for this caching type.');
    }

1293
    if ($access_plugin->usesOptions()) {
merlinofchaos's avatar
merlinofchaos committed
1294 1295 1296
      $options['access']['links']['access_options'] = t('Change settings for this access type.');
    }

1297 1298
    if ($this->usesLinkDisplay()) {
      $display_id = $this->getLinkDisplay();
1299 1300 1301
      $displays = $this->view->storage->get('display');
      $link_display = empty($displays[$display_id]) ? t('None') : check_plain($displays[$display_id]['display_title']);
      $link_display = $this->getOption('link_display') == 'custom_url' ? t('Custom URL') : $link_display;
merlinofchaos's avatar
merlinofchaos committed
1302
      $options['link_display'] = array(
1303
        'category' => 'pager',
merlinofchaos's avatar
merlinofchaos committed
1304 1305 1306 1307 1308 1309
        'title' => t('Link display'),
        'value' => $link_display,
        'desc' => t('Specify which display or custom url this display will link to.'),
      );
    }

1310
    if ($this->usesExposedFormInBlock()) {
merlinofchaos's avatar
merlinofchaos committed
1311 1312 1313
      $options['exposed_block'] = array(
        'category' => 'exposed',
        'title' => t('Exposed form in block'),
1314
        'value' => $this->getOption('exposed_block') ? t('Yes') : t('No'),
merlinofchaos's avatar
merlinofchaos committed
1315 1316 1317 1318
        'desc' => t('Allow the exposed form to appear in a block instead of the view.'),
      );
    }

1319
    $exposed_form_plugin = $this->getPlugin('exposed_form');
merlinofchaos's avatar
merlinofchaos committed
1320 1321
    if (!$exposed_form_plugin) {
      // default to the no cache control plugin.
1322
      $exposed_form_plugin = Views::pluginManager('exposed_form')->createInstance('basic');
merlinofchaos's avatar
merlinofchaos committed
1323 1324
    }

1325
    $exposed_form_str = $exposed_form_plugin->summaryTitle();
merlinofchaos's avatar
merlinofchaos committed
1326 1327 1328 1329

    $options['exposed_form'] = array(
      'category' => 'exposed',
      'title' => t('Exposed form style'),
1330
      'value' => $exposed_form_plugin->pluginTitle(),
merlinofchaos's avatar
merlinofchaos committed
1331 1332 1333 1334
      'setting' => $exposed_form_str,
      'desc' => t('Select the kind of exposed filter to use.'),
    );