You are here

function views_plugin_display::options_form in Views (for Drupal 7) 6.2

Same name and namespace in other branches
  1. 6.3 plugins/views_plugin_display.inc \views_plugin_display::options_form()
  2. 7.3 plugins/views_plugin_display.inc \views_plugin_display::options_form()

Provide the default form for setting options.

Overrides views_plugin::options_form

3 calls to views_plugin_display::options_form()
views_plugin_display_attachment::options_form in plugins/views_plugin_display_attachment.inc
Provide the default form for setting options.
views_plugin_display_block::options_form in plugins/views_plugin_display_block.inc
Provide the default form for setting options.
views_plugin_display_page::options_form in plugins/views_plugin_display_page.inc
Provide the default form for setting options.
3 methods override views_plugin_display::options_form()
views_plugin_display_attachment::options_form in plugins/views_plugin_display_attachment.inc
Provide the default form for setting options.
views_plugin_display_block::options_form in plugins/views_plugin_display_block.inc
Provide the default form for setting options.
views_plugin_display_page::options_form in plugins/views_plugin_display_page.inc
Provide the default form for setting options.

File

plugins/views_plugin_display.inc, line 888
Contains the base display plugin.

Class

views_plugin_display
The default display plugin handler. Display plugins handle options and basic mechanisms for different output methods.

Code

function options_form(&$form, &$form_state) {
  if ($this
    ->defaultable_sections($form_state['section'])) {
    $this
      ->add_override_button($form, $form_state, $form_state['section']);
  }
  $form['#title'] = check_plain($this->display->display_title) . ': ';

  // Set the 'section' to hilite 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'][$form_state['section']])) {
    $form['#section'] = 'default-' . $form_state['section'];
  }
  else {
    $form['#section'] = $this->display->id . '-' . $form_state['section'];
  }
  switch ($form_state['section']) {
    case 'display_title':
      $form['#title'] .= t('The name of this display');
      $form['display_title'] = array(
        '#type' => 'textfield',
        '#description' => t('This title will appear only in the administrative interface for the View.'),
        '#default_value' => $this->display->display_title,
      );
      break;
    case 'title':
      $form['#title'] .= t('The title of this view');
      $form['title'] = array(
        '#type' => 'textfield',
        '#description' => 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
          ->get_option('title'),
      );
      break;
    case 'css_class':
      $form['#title'] .= t('CSS class');
      $form['css_class'] = array(
        '#type' => 'textfield',
        '#description' => t('The CSS class names will be added to the view. This enables you to use specific CSS code for each view. You may define multiples classes separated by spaces.'),
        '#default_value' => $this
          ->get_option('css_class'),
      );
      break;
    case 'use_ajax':
      $form['#title'] .= t('Use AJAX when available to load this view');
      $form['description'] = array(
        '#prefix' => '<div class="description form-item">',
        '#suffix' => '</div>',
        '#value' => t('If set, this view will use an AJAX mechanism for paging, table sorting and exposed filters. This means the entire page will not refresh. It is not recommended that you use this if this view is the main content of the page as it will prevent deep linking to specific pages, but it is very useful for side content.'),
      );
      $form['use_ajax'] = array(
        '#type' => 'radios',
        '#options' => array(
          1 => t('Yes'),
          0 => t('No'),
        ),
        '#default_value' => $this
          ->get_option('use_ajax') ? 1 : 0,
      );
      break;
    case 'use_pager':
      $form['#title'] .= t('Use a pager for this view');
      $form['use_pager'] = array(
        '#type' => 'radios',
        '#options' => array(
          TRUE => t('Full pager'),
          'mini' => t('Mini pager'),
          0 => t('No'),
        ),
        '#default_value' => $this
          ->get_option('use_pager'),
      );
      $form['pager_element'] = array(
        '#type' => 'textfield',
        '#title' => t('Pager element'),
        '#description' => t("Unless you're experiencing problems with pagers related to this view, you should leave this at 0. If using multiple pagers on one page you may need to set this number to a higher value so as not to conflict within the ?page= array. Large values will add a lot of commas to your URLs, so avoid if possible."),
        '#default_value' => intval($this
          ->get_option('pager_element')),
      );
      break;
    case 'items_per_page':
      $form['#title'] .= $this
        ->use_pager() ? t('Items per page') : t('Items to display');
      $form['items_per_page'] = array(
        '#type' => 'textfield',
        '#description' => t('The number of items to display per page. Enter 0 for no limit.'),
        '#default_value' => intval($this
          ->get_option('items_per_page')),
      );
      $form['offset'] = array(
        '#type' => 'textfield',
        '#title' => t('Offset'),
        '#description' => t('The number of items to skip. For example, if this field is 3, the first 3 items will be skipped and not displayed. Offset can not be used if items to display is 0; instead use a very large number there.'),
        '#default_value' => intval($this
          ->get_option('offset')),
      );
      break;
    case 'use_more':
      $form['#title'] .= t('Add a more link to the bottom of the display.');
      $form['use_more'] = array(
        '#type' => 'checkbox',
        '#title' => t('Create more link'),
        '#description' => 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' above."),
        '#default_value' => $this
          ->get_option('use_more'),
      );
      $form['use_more_always'] = array(
        '#type' => 'checkbox',
        '#title' => t('Always display more link'),
        '#description' => t("This will display the more link even if there are no more items to display."),
        '#default_value' => $this
          ->get_option('use_more_always'),
      );
      $form['use_more_text'] = array(
        '#type' => 'textfield',
        '#title' => t('More link text'),
        '#description' => t("The text to display for the more link."),
        '#default_value' => $this
          ->get_option('use_more_text'),
      );
      break;
    case 'distinct':
      $form['#title'] .= t('Display only distinct items, without duplicates.');
      $form['distinct'] = array(
        '#type' => 'checkbox',
        '#title' => t('Distinct'),
        '#description' => t('This will make the view display only distinct items. If there are multiple identical items, each will be displayed only once. You can use this to try and remove duplicates from a view, though it does not always work. Note that this can slow queries down, so use it with caution.'),
        '#default_value' => $this
          ->get_option('distinct'),
      );
      break;
    case 'access':
      $form['#title'] .= t('Access restrictions');
      $form['access'] = array(
        '#prefix' => '<div class="clear-block">',
        '#suffix' => '</div>',
        '#tree' => TRUE,
      );
      $access = $this
        ->get_option('access');
      $form['access']['type'] = array(
        '#type' => 'radios',
        '#options' => views_fetch_plugin_names('access'),
        '#default_value' => $access['type'],
      );
      $access_plugin = views_fetch_plugin_data('access', $access['type']);
      if (!empty($access_plugin['uses options'])) {
        $form['markup'] = array(
          '#prefix' => '<div class="form-item description">',
          '#suffix' => '</div>',
          '#value' => t('You may also adjust the !settings for the currently selected access restriction by clicking on the icon.', array(
            '!settings' => $this
              ->option_link(t('settings'), 'access_options'),
          )),
        );
      }
      break;
    case 'access_options':
      $access = $this
        ->get_option('access');
      $plugin = $this
        ->get_access_plugin();
      $form['#title'] .= t('Access options');
      if ($plugin) {
        $form['#help_topic'] = $plugin->definition['help topic'];
        $form['#help_module'] = $plugin->definition['module'];
        $form['access_options'] = array(
          '#tree' => TRUE,
        );
        $form['access_options']['type'] = array(
          '#type' => 'value',
          '#value' => $access['type'],
        );
        $plugin
          ->options_form($form['access_options'], $form_state);
      }
      break;
    case 'cache':
      $form['#title'] .= t('Caching');
      $form['cache'] = array(
        '#prefix' => '<div class="clear-block">',
        '#suffix' => '</div>',
        '#tree' => TRUE,
      );
      $cache = $this
        ->get_option('cache');
      $form['cache']['type'] = array(
        '#type' => 'radios',
        '#options' => views_fetch_plugin_names('cache'),
        '#default_value' => $cache['type'],
      );
      $cache_plugin = views_fetch_plugin_data('cache', $cache['type']);
      if (!empty($cache_plugin['uses options'])) {
        $form['markup'] = array(
          '#prefix' => '<div class="form-item description">',
          '#suffix' => '</div>',
          '#value' => t('You may also adjust the !settings for the currently selected cache mechanism by clicking on the icon.', array(
            '!settings' => $this
              ->option_link(t('settings'), 'cache_options'),
          )),
        );
      }
      break;
    case 'cache_options':
      $cache = $this
        ->get_option('cache');
      $plugin = $this
        ->get_cache_plugin();
      $form['#title'] .= t('Caching options');
      if ($plugin) {
        $form['#help_topic'] = $plugin->definition['help topic'];
        $form['#help_module'] = $plugin->definition['module'];
        $form['cache_options'] = array(
          '#tree' => TRUE,
        );
        $form['cache_options']['type'] = array(
          '#type' => 'value',
          '#value' => $cache['type'],
        );
        $plugin
          ->options_form($form['cache_options'], $form_state);
      }
      break;
    case 'header':
      $form['#title'] .= t('Header');
      $form['header_empty'] = array(
        '#type' => 'checkbox',
        '#title' => t('Display even if view has no result'),
        '#default_value' => $this
          ->get_option('header_empty'),
      );
      $form['header'] = array(
        '#type' => 'textarea',
        '#default_value' => $this
          ->get_option('header'),
        '#rows' => 6,
        '#description' => t('Text to display at the top of the view. May contain an explanation or links or whatever you like. Optional.'),
      );
      $form['header_format'] = filter_form($this
        ->get_option('header_format'), NULL, array(
        'header_format',
      ));
      break;
    case 'footer':
      $form['#title'] .= t('Footer');
      $form['footer_empty'] = array(
        '#type' => 'checkbox',
        '#title' => t('Display even if view has no result'),
        '#default_value' => $this
          ->get_option('footer_empty'),
      );
      $form['footer'] = array(
        '#type' => 'textarea',
        '#default_value' => $this
          ->get_option('footer'),
        '#rows' => 6,
        '#description' => t('Text to display beneath the view. May contain an explanation or links or whatever you like. Optional.'),
      );
      $form['footer_format'] = filter_form($this
        ->get_option('footer_format'), NULL, array(
        'footer_format',
      ));
      break;
    case 'empty':
      $form['#title'] .= t('Empty text');
      $form['empty'] = array(
        '#type' => 'textarea',
        '#default_value' => $this
          ->get_option('empty'),
        '#rows' => 6,
        '#description' => t('Text to display if the view has no results. Optional.'),
      );
      $form['empty_format'] = filter_form($this
        ->get_option('empty_format'), NULL, array(
        'empty_format',
      ));
      break;
    case 'style_plugin':
      $form['#title'] .= t('How should this view be styled');
      $form['#help_topic'] = 'style';
      $form['style_plugin'] = array(
        '#type' => 'radios',
        '#options' => views_fetch_plugin_names('style', $this
          ->get_style_type(), array(
          $this->view->base_table,
        )),
        '#default_value' => $this
          ->get_option('style_plugin'),
        '#description' => 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.'),
      );
      $style_plugin = views_fetch_plugin_data('style', $this
        ->get_option('style_plugin'));
      if (!empty($style_plugin['uses options'])) {
        $form['markup'] = array(
          '#prefix' => '<div class="form-item description">',
          '#suffix' => '</div>',
          '#value' => t('You may also adjust the !settings for the currently selected style by clicking on the icon.', array(
            '!settings' => $this
              ->option_link(t('settings'), 'style_options'),
          )),
        );
      }
      break;
    case 'style_options':
      $form['#title'] .= t('Style options');
      $style = TRUE;
      $type = 'style_plugin';
      $name = $this
        ->get_option('style_plugin');
    case 'row_options':
      if (!isset($name)) {
        $name = $this
          ->get_option('row_plugin');
      }

      // if row, $style will be empty.
      if (empty($style)) {
        $form['#title'] .= t('Row style options');
        $type = 'row_plugin';
      }
      $plugin = $this
        ->get_plugin(empty($style) ? 'row' : 'style');
      if ($plugin) {
        if (isset($plugin->definition['help topic'])) {
          $form['#help_topic'] = $plugin->definition['help topic'];
          $form['#help_module'] = $plugin->definition['module'];
        }
        $form[$form_state['section']] = array(
          '#tree' => TRUE,
        );
        $plugin
          ->options_form($form[$form_state['section']], $form_state);
      }
      break;
    case 'row_plugin':
      $form['#title'] .= t('How should each row in this view be styled');
      $form['#help_topic'] = 'style-row';
      $form['row_plugin'] = array(
        '#type' => 'radios',
        '#options' => views_fetch_plugin_names('row', $this
          ->get_style_type(), array(
          $this->view->base_table,
        )),
        '#default_value' => $this
          ->get_option('row_plugin'),
      );
      $row_plugin = views_fetch_plugin_data('row', $this
        ->get_option('row_plugin'));
      if (!empty($row_plugin['uses options'])) {
        $form['markup'] = array(
          '#prefix' => '<div class="form-item description">',
          '#suffix' => '</div>',
          '#value' => t('You may also adjust the !settings for the currently selected row style by clicking on the icon.', array(
            '!settings' => $this
              ->option_link(t('settings'), 'row_options'),
          )),
        );
      }
      break;
    case 'link_display':
      $form['#title'] .= t('Which display to use for path');
      foreach ($this->view->display as $display_id => $display) {
        if ($display->handler
          ->has_path()) {
          $options[$display_id] = $display->display_title;
        }
      }
      $form['link_display'] = array(
        '#type' => 'radios',
        '#options' => $options,
        '#description' => 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
          ->get_link_display(),
      );
      break;
    case 'analyze-theme':
      $form['#title'] .= t('Theming information');
      $form['#help_topic'] = 'analyze-theme';
      if (isset($_POST['theme'])) {
        $this->view->theme = $_POST['theme'];
      }
      else {
        if (empty($this->view->theme)) {
          $this->view->theme = variable_get('theme_default', 'garland');
        }
      }
      global $custom_theme;
      $custom_theme = $this->view->theme;
      init_theme();
      $funcs = array();

      // Get theme functions for the display. Note that some displays may
      // not have themes. The 'feed' display, for example, completely
      // delegates to the style.
      if (!empty($this->definition['theme'])) {
        $funcs[] = $this
          ->option_link(t('Display output'), 'analyze-theme-display') . ': ' . $this
          ->format_themes($this
          ->theme_functions());
        $themes = $this
          ->additional_theme_functions();
        if ($themes) {
          foreach ($themes as $theme) {
            $funcs[] = $this
              ->option_link(t('Alternative display output'), 'analyze-theme-display') . ': ' . $this
              ->format_themes($theme);
          }
        }
      }
      $plugin = $this
        ->get_plugin();
      if ($plugin) {
        $funcs[] = $this
          ->option_link(t('Style output'), 'analyze-theme-style') . ': ' . $this
          ->format_themes($plugin
          ->theme_functions(), $plugin
          ->additional_theme_functions());
        $themes = $plugin
          ->additional_theme_functions();
        if ($themes) {
          foreach ($themes as $theme) {
            $funcs[] = $this
              ->option_link(t('Alternative style'), 'analyze-theme-style') . ': ' . $this
              ->format_themes($theme);
          }
        }
        if ($plugin
          ->uses_row_plugin()) {
          $row_plugin = $this
            ->get_plugin('row');
          if ($row_plugin) {
            $funcs[] = $this
              ->option_link(t('Row style output'), 'analyze-theme-row') . ': ' . $this
              ->format_themes($row_plugin
              ->theme_functions());
            $themes = $row_plugin
              ->additional_theme_functions();
            if ($themes) {
              foreach ($themes as $theme) {
                $funcs[] = $this
                  ->option_link(t('Alternative row style'), 'analyze-theme-row') . ': ' . $this
                  ->format_themes($theme);
              }
            }
          }
        }
        if ($plugin
          ->uses_fields()) {
          foreach ($this
            ->get_handlers('field') as $id => $handler) {
            $funcs[] = $this
              ->option_link(t('Field @field (ID: @id)', array(
              '@field' => $handler
                ->ui_name(),
              '@id' => $id,
            )), 'analyze-theme-field') . ': ' . $this
              ->format_themes($handler
              ->theme_functions());
          }
        }
      }
      $form['important'] = array(
        '#prefix' => '<div class="form-item description">',
        '#suffix' => '</div>',
        '#value' => '<p>' . t('This section lists all possible templates for the display plugin and for the style plugins, ordered roughly from the least specific to the most specific. The active template for each plugin -- which is the most specific template found on the system -- is highlighted in bold.') . '</p>',
      );
      foreach (list_themes() as $key => $theme) {
        $options[$key] = $theme->info['name'];
      }
      $form['box'] = array(
        '#prefix' => '<div class="container-inline">',
        '#suffix' => '</div>',
      );
      $form['box']['theme'] = array(
        '#type' => 'select',
        '#options' => $options,
        '#default_value' => $this->view->theme,
      );
      $form['box']['change'] = array(
        '#type' => 'submit',
        '#value' => t('Change theme'),
        '#submit' => array(
          'views_ui_edit_display_form_change_theme',
        ),
      );
      $form['analysis'] = array(
        '#prefix' => '<div class="form-item">',
        '#suffix' => '</div>',
        '#value' => theme('item_list', $funcs),
      );
      $form['rescan_button'] = array(
        '#prefix' => '<div class="form-item">',
        '#suffix' => '</div>',
      );
      $form['rescan_button']['button'] = array(
        '#type' => 'submit',
        '#value' => t('Rescan template files'),
        '#submit' => array(
          'views_ui_config_item_form_rescan',
        ),
      );
      $form['rescan_button']['markup'] = array(
        '#prefix' => '<div class="description">',
        '#suffix' => '</div>',
        '#value' => t("<strong>Important!</strong> When adding, removing, or renaming template files, it is necessary to make Drupal aware of the changes by making it rescan the files on your system. By clicking this button you clear Drupal's theme registry and thereby trigger this rescanning process. The highlighted templates above will then reflect the new state of your system."),
      );
      $form_state['ok_button'] = TRUE;
      break;
    case 'analyze-theme-display':
      $form['#title'] .= t('Theming information (display)');
      $output = '<p>' . t('Back to !info.', array(
        '!info' => $this
          ->option_link(t('theming information'), 'analyze-theme'),
      )) . '</p>';
      if (empty($this->definition['theme'])) {
        $output .= t('This display has no theming information');
      }
      else {
        $output .= '<p>' . t('This is the default theme template used for this display.') . '</p>';
        $output .= '<pre>' . check_plain(file_get_contents('./' . $this->definition['theme path'] . '/' . strtr($this->definition['theme'], '_', '-') . '.tpl.php')) . '</pre>';
      }
      if (!empty($this->definition['additional themes'])) {
        foreach ($this->definition['additional themes'] as $theme => $type) {
          $output .= '<p>' . t('This is an alternative template for this display.') . '</p>';
          $output .= '<pre>' . check_plain(file_get_contents('./' . $this->definition['theme path'] . '/' . strtr($theme, '_', '-') . '.tpl.php')) . '</pre>';
        }
      }
      $form['analysis'] = array(
        '#prefix' => '<div class="form-item">',
        '#suffix' => '</div>',
        '#value' => $output,
      );
      $form_state['ok_button'] = TRUE;
      break;
    case 'analyze-theme-style':
      $form['#title'] .= t('Theming information (style)');
      $output = '<p>' . t('Back to !info.', array(
        '!info' => $this
          ->option_link(t('theming information'), 'analyze-theme'),
      )) . '</p>';
      $plugin = $this
        ->get_plugin();
      if (empty($plugin->definition['theme'])) {
        $output .= t('This display has no style theming information');
      }
      else {
        $output .= '<p>' . t('This is the default theme template used for this style.') . '</p>';
        $output .= '<pre>' . check_plain(file_get_contents('./' . $plugin->definition['theme path'] . '/' . strtr($plugin->definition['theme'], '_', '-') . '.tpl.php')) . '</pre>';
      }
      if (!empty($plugin->definition['additional themes'])) {
        foreach ($plugin->definition['additional themes'] as $theme => $type) {
          $output .= '<p>' . t('This is an alternative template for this style.') . '</p>';
          $output .= '<pre>' . check_plain(file_get_contents('./' . $plugin->definition['theme path'] . '/' . strtr($theme, '_', '-') . '.tpl.php')) . '</pre>';
        }
      }
      $form['analysis'] = array(
        '#prefix' => '<div class="form-item">',
        '#suffix' => '</div>',
        '#value' => $output,
      );
      $form_state['ok_button'] = TRUE;
      break;
    case 'analyze-theme-row':
      $form['#title'] .= t('Theming information (row style)');
      $output = '<p>' . t('Back to !info.', array(
        '!info' => $this
          ->option_link(t('theming information'), 'analyze-theme'),
      )) . '</p>';
      $plugin = $this
        ->get_plugin('row');
      if (empty($plugin->definition['theme'])) {
        $output .= t('This display has no row style theming information');
      }
      else {
        $output .= '<p>' . t('This is the default theme template used for this row style.') . '</p>';
        $output .= '<pre>' . check_plain(file_get_contents('./' . $plugin->definition['theme path'] . '/' . strtr($plugin->definition['theme'], '_', '-') . '.tpl.php')) . '</pre>';
      }
      if (!empty($plugin->definition['additional themes'])) {
        foreach ($plugin->definition['additional themes'] as $theme => $type) {
          $output .= '<p>' . t('This is an alternative template for this row style.') . '</p>';
          $output .= '<pre>' . check_plain(file_get_contents('./' . $plugin->definition['theme path'] . '/' . strtr($theme, '_', '-') . '.tpl.php')) . '</pre>';
        }
      }
      $form['analysis'] = array(
        '#prefix' => '<div class="form-item">',
        '#suffix' => '</div>',
        '#value' => $output,
      );
      $form_state['ok_button'] = TRUE;
      break;
    case 'analyze-theme-field':
      $form['#title'] .= t('Theming information (row style)');
      $output = '<p>' . t('Back to !info.', array(
        '!info' => $this
          ->option_link(t('theming information'), 'analyze-theme'),
      )) . '</p>';
      $output .= '<p>' . t('This is the default theme template used for this row style.') . '</p>';

      // Field templates aren't registered the normal way...and they're always
      // this one, anyhow.
      $output .= '<pre>' . check_plain(file_get_contents(drupal_get_path('module', 'views') . '/theme/views-view-field.tpl.php')) . '</pre>';
      $form['analysis'] = array(
        '#prefix' => '<div class="form-item">',
        '#suffix' => '</div>',
        '#value' => $output,
      );
      $form_state['ok_button'] = TRUE;
      break;
    case 'exposed_block':
      $form['#title'] .= t('Put the exposed form in a block');
      $form['description'] = array(
        '#prefix' => '<div class="description form-item">',
        '#suffix' => '</div>',
        '#value' => 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.'),
      );
      $form['exposed_block'] = array(
        '#type' => 'radios',
        '#options' => array(
          1 => t('Yes'),
          0 => t('No'),
        ),
        '#default_value' => $this
          ->get_option('exposed_block') ? 1 : 0,
      );
      break;
  }
}