You are here

public function DisplayPluginBase::buildOptionsForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::buildOptionsForm()

Provide a form to edit options for this plugin.

Overrides PluginBase::buildOptionsForm

4 calls to DisplayPluginBase::buildOptionsForm()
Attachment::buildOptionsForm in core/modules/views/src/Plugin/views/display/Attachment.php
Provide the default form for setting options.
Block::buildOptionsForm in core/modules/views/src/Plugin/views/display/Block.php
Provide the default form for setting options.
DisplayTest::buildOptionsForm in core/modules/views/tests/modules/views_test_data/src/Plugin/views/display/DisplayTest.php
Provide a form to edit options for this plugin.
PathPluginBase::buildOptionsForm in core/modules/views/src/Plugin/views/display/PathPluginBase.php
Provide a form to edit options for this plugin.
4 methods override DisplayPluginBase::buildOptionsForm()
Attachment::buildOptionsForm in core/modules/views/src/Plugin/views/display/Attachment.php
Provide the default form for setting options.
Block::buildOptionsForm in core/modules/views/src/Plugin/views/display/Block.php
Provide the default form for setting options.
DisplayTest::buildOptionsForm in core/modules/views/tests/modules/views_test_data/src/Plugin/views/display/DisplayTest.php
Provide a form to edit options for this plugin.
PathPluginBase::buildOptionsForm in core/modules/views/src/Plugin/views/display/PathPluginBase.php
Provide a form to edit options for this plugin.

File

core/modules/views/src/Plugin/views/display/DisplayPluginBase.php, line 1387
Contains \Drupal\views\Plugin\views\display\DisplayPluginBase.

Class

DisplayPluginBase
Base class for views display plugins.

Namespace

Drupal\views\Plugin\views\display

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $section = $form_state
    ->get('section');
  if ($this
    ->defaultableSections($section)) {
    views_ui_standard_display_dropdown($form, $form_state, $section);
  }
  $form['#title'] = $this->display['display_title'] . ': ';

  // Set the 'section' to highlight on the form.
  // If it's the item we're looking at is pulling from the default display,
  // reflect that. Don't use is_defaulted since we want it to show up even
  // on the default display.
  if (!empty($this->options['defaults'][$section])) {
    $form['#section'] = 'default-' . $section;
  }
  else {
    $form['#section'] = $this->display['id'] . '-' . $section;
  }
  switch ($section) {
    case 'display_id':
      $form['#title'] .= $this
        ->t('The machine name of this display');
      $form['display_id'] = array(
        '#type' => 'textfield',
        '#title' => $this
          ->t('Machine name of the display'),
        '#default_value' => !empty($this->display['new_id']) ? $this->display['new_id'] : $this->display['id'],
        '#required' => TRUE,
        '#size' => 64,
      );
      break;
    case 'display_title':
      $form['#title'] .= $this
        ->t('The name and the description of this display');
      $form['display_title'] = array(
        '#title' => $this
          ->t('Administrative name'),
        '#type' => 'textfield',
        '#default_value' => $this->display['display_title'],
      );
      $form['display_description'] = array(
        '#title' => $this
          ->t('Administrative description'),
        '#type' => 'textfield',
        '#default_value' => $this
          ->getOption('display_description'),
      );
      break;
    case 'display_comment':
      $form['#title'] .= $this
        ->t('Administrative comment');
      $form['display_comment'] = array(
        '#type' => 'textarea',
        '#title' => $this
          ->t('Administrative comment'),
        '#description' => $this
          ->t('This description will only be seen within the administrative interface and can be used to document this display.'),
        '#default_value' => $this
          ->getOption('display_comment'),
      );
      break;
    case 'title':
      $form['#title'] .= $this
        ->t('The title of this view');
      $form['title'] = array(
        '#title' => $this
          ->t('Title'),
        '#type' => 'textfield',
        '#description' => $this
          ->t('This title will be displayed with the view, wherever titles are normally displayed; i.e, as the page title, block title, etc.'),
        '#default_value' => $this
          ->getOption('title'),
        '#maxlength' => 255,
      );
      break;
    case 'css_class':
      $form['#title'] .= $this
        ->t('CSS class');
      $form['css_class'] = array(
        '#type' => 'textfield',
        '#title' => $this
          ->t('CSS class name(s)'),
        '#description' => $this
          ->t('Separate multiple classes by spaces.'),
        '#default_value' => $this
          ->getOption('css_class'),
      );
      break;
    case 'use_ajax':
      $form['#title'] .= $this
        ->t('AJAX');
      $form['use_ajax'] = array(
        '#description' => $this
          ->t('Options such as paging, table sorting, and exposed filters will not initiate a page refresh.'),
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Use AJAX'),
        '#default_value' => $this
          ->getOption('use_ajax') ? 1 : 0,
      );
      break;
    case 'hide_attachment_summary':
      $form['#title'] .= $this
        ->t('Hide attachments when displaying a contextual filter summary');
      $form['hide_attachment_summary'] = array(
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Hide attachments in summary'),
        '#default_value' => $this
          ->getOption('hide_attachment_summary') ? 1 : 0,
      );
      break;
    case 'show_admin_links':
      $form['#title'] .= $this
        ->t('Show contextual links on this view.');
      $form['show_admin_links'] = array(
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Show contextual links'),
        '#default_value' => $this
          ->getOption('show_admin_links'),
      );
      break;
    case 'use_more':
      $form['#title'] .= $this
        ->t('Add a more link to the bottom of the display.');
      $form['use_more'] = array(
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Create more link'),
        '#description' => $this
          ->t("This will add a more link to the bottom of this view, which will link to the page view. If you have more than one page view, the link will point to the display specified in 'Link display' section under pager. You can override the url at the link display setting."),
        '#default_value' => $this
          ->getOption('use_more'),
      );
      $form['use_more_always'] = array(
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Always display the more link'),
        '#description' => $this
          ->t('Check this to display the more link even if there are no more items to display.'),
        '#default_value' => $this
          ->getOption('use_more_always'),
        '#states' => array(
          'visible' => array(
            ':input[name="use_more"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['use_more_text'] = array(
        '#type' => 'textfield',
        '#title' => $this
          ->t('More link text'),
        '#description' => $this
          ->t('The text to display for the more link.'),
        '#default_value' => $this
          ->getOption('use_more_text'),
        '#states' => array(
          'visible' => array(
            ':input[name="use_more"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      break;
    case 'group_by':
      $form['#title'] .= $this
        ->t('Allow grouping and aggregation (calculation) of fields.');
      $form['group_by'] = array(
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Aggregate'),
        '#description' => $this
          ->t('If enabled, some fields may become unavailable. All fields that are selected for grouping will be collapsed to one record per distinct value. Other fields which are selected for aggregation will have the function run on them. For example, you can group nodes on title and count the number of nids in order to get a list of duplicate titles.'),
        '#default_value' => $this
          ->getOption('group_by'),
      );
      break;
    case 'access':
      $form['#title'] .= $this
        ->t('Access restrictions');
      $form['access'] = array(
        '#prefix' => '<div class="clearfix">',
        '#suffix' => '</div>',
        '#tree' => TRUE,
      );
      $access = $this
        ->getOption('access');
      $form['access']['type'] = array(
        '#title' => $this
          ->t('Access'),
        '#title_display' => 'invisible',
        '#type' => 'radios',
        '#options' => Views::fetchPluginNames('access', $this
          ->getType(), array(
          $this->view->storage
            ->get('base_table'),
        )),
        '#default_value' => $access['type'],
      );
      $access_plugin = $this
        ->getPlugin('access');
      if ($access_plugin
        ->usesOptions()) {
        $form['markup'] = array(
          '#prefix' => '<div class="js-form-item form-item description">',
          '#markup' => $this
            ->t('You may also adjust the @settings for the currently selected access restriction.', array(
            '@settings' => $this
              ->optionLink($this
              ->t('settings'), 'access_options'),
          )),
          '#suffix' => '</div>',
        );
      }
      break;
    case 'access_options':
      $plugin = $this
        ->getPlugin('access');
      $form['#title'] .= $this
        ->t('Access options');
      if ($plugin) {
        $form['access_options'] = array(
          '#tree' => TRUE,
        );
        $plugin
          ->buildOptionsForm($form['access_options'], $form_state);
      }
      break;
    case 'cache':
      $form['#title'] .= $this
        ->t('Caching');
      $form['cache'] = array(
        '#prefix' => '<div class="clearfix">',
        '#suffix' => '</div>',
        '#tree' => TRUE,
      );
      $cache = $this
        ->getOption('cache');
      $form['cache']['type'] = array(
        '#title' => $this
          ->t('Caching'),
        '#title_display' => 'invisible',
        '#type' => 'radios',
        '#options' => Views::fetchPluginNames('cache', $this
          ->getType(), array(
          $this->view->storage
            ->get('base_table'),
        )),
        '#default_value' => $cache['type'],
      );
      $cache_plugin = $this
        ->getPlugin('cache');
      if ($cache_plugin
        ->usesOptions()) {
        $form['markup'] = array(
          '#prefix' => '<div class="js-form-item form-item description">',
          '#suffix' => '</div>',
          '#markup' => $this
            ->t('You may also adjust the @settings for the currently selected cache mechanism.', array(
            '@settings' => $this
              ->optionLink($this
              ->t('settings'), 'cache_options'),
          )),
        );
      }
      break;
    case 'cache_options':
      $plugin = $this
        ->getPlugin('cache');
      $form['#title'] .= $this
        ->t('Caching options');
      if ($plugin) {
        $form['cache_options'] = array(
          '#tree' => TRUE,
        );
        $plugin
          ->buildOptionsForm($form['cache_options'], $form_state);
      }
      break;
    case 'query':
      $query_options = $this
        ->getOption('query');
      $plugin_name = $query_options['type'];
      $form['#title'] .= $this
        ->t('Query options');
      $this->view
        ->initQuery();
      if ($this->view->query) {
        $form['query'] = array(
          '#tree' => TRUE,
          'type' => array(
            '#type' => 'value',
            '#value' => $plugin_name,
          ),
          'options' => array(
            '#tree' => TRUE,
          ),
        );
        $this->view->query
          ->buildOptionsForm($form['query']['options'], $form_state);
      }
      break;
    case 'rendering_language':
      $form['#title'] .= $this
        ->t('Rendering language');
      if (\Drupal::languageManager()
        ->isMultilingual() && $this
        ->isBaseTableTranslatable()) {
        $options = $this
          ->buildRenderingLanguageOptions();
        $form['rendering_language'] = array(
          '#type' => 'select',
          '#options' => $options,
          '#title' => $this
            ->t('Rendering language'),
          '#description' => $this
            ->t('All content that supports translations will be displayed in the selected language.'),
          '#default_value' => $this
            ->getOption('rendering_language'),
        );
      }
      else {
        $form['rendering_language']['#markup'] = $this
          ->t('The view is not based on a translatable entity type or the site is not multilingual.');
      }
      break;
    case 'style':
      $form['#title'] .= $this
        ->t('How should this view be styled');
      $style_plugin = $this
        ->getPlugin('style');
      $form['style'] = array(
        '#prefix' => '<div class="clearfix">',
        '#suffix' => '</div>',
        '#tree' => TRUE,
      );
      $form['style']['type'] = array(
        '#title' => $this
          ->t('Style'),
        '#title_display' => 'invisible',
        '#type' => 'radios',
        '#options' => Views::fetchPluginNames('style', $this
          ->getType(), array(
          $this->view->storage
            ->get('base_table'),
        )),
        '#default_value' => $style_plugin->definition['id'],
        '#description' => $this
          ->t('If the style you choose has settings, be sure to click the settings button that will appear next to it in the View summary.'),
      );
      if ($style_plugin
        ->usesOptions()) {
        $form['markup'] = array(
          '#prefix' => '<div class="js-form-item form-item description">',
          '#suffix' => '</div>',
          '#markup' => $this
            ->t('You may also adjust the @settings for the currently selected style.', array(
            '@settings' => $this
              ->optionLink($this
              ->t('settings'), 'style_options'),
          )),
        );
      }
      break;
    case 'style_options':
      $form['#title'] .= $this
        ->t('Style options');
      $style = TRUE;
      $style_plugin = $this
        ->getOption('style');
      $name = $style_plugin['type'];
    case 'row_options':
      if (!isset($name)) {
        $row_plugin = $this
          ->getOption('row');
        $name = $row_plugin['type'];
      }

      // If row, $style will be empty.
      if (empty($style)) {
        $form['#title'] .= $this
          ->t('Row style options');
      }
      $plugin = $this
        ->getPlugin(empty($style) ? 'row' : 'style', $name);
      if ($plugin) {
        $form[$section] = [
          '#tree' => TRUE,
        ];
        $plugin
          ->buildOptionsForm($form[$section], $form_state);
      }
      break;
    case 'row':
      $form['#title'] .= $this
        ->t('How should each row in this view be styled');
      $row_plugin_instance = $this
        ->getPlugin('row');
      $form['row'] = array(
        '#prefix' => '<div class="clearfix">',
        '#suffix' => '</div>',
        '#tree' => TRUE,
      );
      $form['row']['type'] = array(
        '#title' => $this
          ->t('Row'),
        '#title_display' => 'invisible',
        '#type' => 'radios',
        '#options' => Views::fetchPluginNames('row', $this
          ->getType(), array(
          $this->view->storage
            ->get('base_table'),
        )),
        '#default_value' => $row_plugin_instance->definition['id'],
      );
      if ($row_plugin_instance
        ->usesOptions()) {
        $form['markup'] = array(
          '#prefix' => '<div class="js-form-item form-item description">',
          '#suffix' => '</div>',
          '#markup' => $this
            ->t('You may also adjust the @settings for the currently selected row style.', array(
            '@settings' => $this
              ->optionLink($this
              ->t('settings'), 'row_options'),
          )),
        );
      }
      break;
    case 'link_display':
      $form['#title'] .= $this
        ->t('Which display to use for path');
      $options = array(
        FALSE => $this
          ->t('None'),
        'custom_url' => $this
          ->t('Custom URL'),
      );
      foreach ($this->view->storage
        ->get('display') as $display_id => $display) {
        if ($this->view->displayHandlers
          ->get($display_id)
          ->hasPath()) {
          $options[$display_id] = $display['display_title'];
        }
      }
      $form['link_display'] = array(
        '#type' => 'radios',
        '#options' => $options,
        '#description' => $this
          ->t("Which display to use to get this display's path for things like summary links, rss feed links, more links, etc."),
        '#default_value' => $this
          ->getOption('link_display'),
      );
      $options = array();
      $optgroup_arguments = (string) t('Arguments');
      foreach ($this->view->display_handler
        ->getHandlers('argument') as $arg => $handler) {
        $options[$optgroup_arguments]["{{ arguments.{$arg} }}"] = $this
          ->t('@argument title', array(
          '@argument' => $handler
            ->adminLabel(),
        ));
        $options[$optgroup_arguments]["{{ raw_arguments.{$arg} }}"] = $this
          ->t('@argument input', array(
          '@argument' => $handler
            ->adminLabel(),
        ));
      }

      // Default text.
      // We have some options, so make a list.
      $description = [];
      $description[] = [
        '#markup' => $this
          ->t('A Drupal path or external URL the more link will point to. Note that this will override the link display setting above.'),
      ];
      if (!empty($options)) {
        $description[] = [
          '#prefix' => '<p>',
          '#markup' => $this
            ->t('The following tokens are available for this link. You may use Twig syntax in this field.'),
          '#suffix' => '</p>',
        ];
        foreach (array_keys($options) as $type) {
          if (!empty($options[$type])) {
            $items = array();
            foreach ($options[$type] as $key => $value) {
              $items[] = $key . ' == ' . $value;
            }
            $item_list = array(
              '#theme' => 'item_list',
              '#items' => $items,
            );
            $description[] = $item_list;
          }
        }
      }
      $form['link_url'] = array(
        '#type' => 'textfield',
        '#title' => $this
          ->t('Custom URL'),
        '#default_value' => $this
          ->getOption('link_url'),
        '#description' => $description,
        '#states' => array(
          'visible' => array(
            ':input[name="link_display"]' => array(
              'value' => 'custom_url',
            ),
          ),
        ),
      );
      break;
    case 'exposed_block':
      $form['#title'] .= $this
        ->t('Put the exposed form in a block');
      $form['description'] = array(
        '#markup' => '<div class="js-form-item form-item description">' . $this
          ->t('If set, any exposed widgets will not appear with this view. Instead, a block will be made available to the Drupal block administration system, and the exposed form will appear there. Note that this block must be enabled manually, Views will not enable it for you.') . '</div>',
      );
      $form['exposed_block'] = array(
        '#type' => 'radios',
        '#options' => array(
          1 => $this
            ->t('Yes'),
          0 => $this
            ->t('No'),
        ),
        '#default_value' => $this
          ->getOption('exposed_block') ? 1 : 0,
      );
      break;
    case 'exposed_form':
      $form['#title'] .= $this
        ->t('Exposed Form');
      $form['exposed_form'] = array(
        '#prefix' => '<div class="clearfix">',
        '#suffix' => '</div>',
        '#tree' => TRUE,
      );
      $exposed_form = $this
        ->getOption('exposed_form');
      $form['exposed_form']['type'] = array(
        '#title' => $this
          ->t('Exposed form'),
        '#title_display' => 'invisible',
        '#type' => 'radios',
        '#options' => Views::fetchPluginNames('exposed_form', $this
          ->getType(), array(
          $this->view->storage
            ->get('base_table'),
        )),
        '#default_value' => $exposed_form['type'],
      );
      $exposed_form_plugin = $this
        ->getPlugin('exposed_form');
      if ($exposed_form_plugin
        ->usesOptions()) {
        $form['markup'] = array(
          '#prefix' => '<div class="js-form-item form-item description">',
          '#suffix' => '</div>',
          '#markup' => $this
            ->t('You may also adjust the @settings for the currently selected style.', array(
            '@settings' => $this
              ->optionLink($this
              ->t('settings'), 'exposed_form_options'),
          )),
        );
      }
      break;
    case 'exposed_form_options':
      $plugin = $this
        ->getPlugin('exposed_form');
      $form['#title'] .= $this
        ->t('Exposed form options');
      if ($plugin) {
        $form['exposed_form_options'] = array(
          '#tree' => TRUE,
        );
        $plugin
          ->buildOptionsForm($form['exposed_form_options'], $form_state);
      }
      break;
    case 'pager':
      $form['#title'] .= $this
        ->t('Select pager');
      $form['pager'] = array(
        '#prefix' => '<div class="clearfix">',
        '#suffix' => '</div>',
        '#tree' => TRUE,
      );
      $pager = $this
        ->getOption('pager');
      $form['pager']['type'] = array(
        '#title' => $this
          ->t('Pager'),
        '#title_display' => 'invisible',
        '#type' => 'radios',
        '#options' => Views::fetchPluginNames('pager', !$this
          ->usesPager() ? 'basic' : NULL, array(
          $this->view->storage
            ->get('base_table'),
        )),
        '#default_value' => $pager['type'],
      );
      $pager_plugin = $this
        ->getPlugin('pager');
      if ($pager_plugin
        ->usesOptions()) {
        $form['markup'] = array(
          '#prefix' => '<div class="js-form-item form-item description">',
          '#suffix' => '</div>',
          '#markup' => $this
            ->t('You may also adjust the @settings for the currently selected pager.', array(
            '@settings' => $this
              ->optionLink($this
              ->t('settings'), 'pager_options'),
          )),
        );
      }
      break;
    case 'pager_options':
      $plugin = $this
        ->getPlugin('pager');
      $form['#title'] .= $this
        ->t('Pager options');
      if ($plugin) {
        $form['pager_options'] = array(
          '#tree' => TRUE,
        );
        $plugin
          ->buildOptionsForm($form['pager_options'], $form_state);
      }
      break;
  }
  foreach ($this->extenders as $extender) {
    $extender
      ->buildOptionsForm($form, $form_state);
  }
}