1.20.x views_plugin_display_block.inc views_plugin_display_block::options_form(&$form, &$form_state)

Provide the default form for setting options.

Overrides views_plugin_display::options_form

File

modules/views/plugins/views_plugin_display_block.inc, line 203
Contains the block display plugin.

Class

views_plugin_display_block
The plugin that handles a block.

Code

function options_form(&$form, &$form_state) {
  // It is very important to call the parent function here:
  parent::options_form($form, $form_state);

  switch ($form_state['section']) {
    case 'block_description':
      $form['#title'] .= t('Block admin label');
      $form['block_description'] = array(
        '#type' => 'textfield',
        '#description' => t('This text is used only in administrative interfaces. It will not be shown to site visitors.'),
        '#default_value' => $this->get_option('block_description'),
      );
      break;

    case 'allow':
      $form['#title'] .= t('Allow settings');
      $form['help'] = array(
        '#type' => 'help',
        '#markup' => t('Checked settings will be available in the Block configuration dialog for modification by the administrator configuring the layout. Unchecked settings will not be available and will only use the settings in this display.'),
      );

      $options = array(
        'use_pager' => t('Use pager'),
        'items_per_page' => t('Items per page'),
        'offset' => t('Pager offset'),
        'link_to_view' => t('Link block title to view page'),
        'more_link' => t('More link'),
        'path_override' => t('Path override'),
        'exposed_form' => t('Use exposed widgets form as block configuration'),
        'fields_override' => t('Fields override'),
      );

      $allow = array_filter($this->get_option('allow'));
      $form['allow'] = array(
        '#type' => 'checkboxes',
        '#default_value' => $allow,
        '#options' => $options,
      );
      break;

    case 'link_to_view':
      $form['#title'] .= t('Link block title to view page');

      $form['link_to_view'] = array(
        '#type' => 'radios',
        '#options' => array(1 => t('Yes'), 0 => t('No')),
        '#default_value' => $this->get_option('link_to_view'),
        '#description' => t('Linking the block title to the view will make an anchor tag to the view page display (if one is exists).'),
      );
      break;

    case 'inherit_path':
      $form['#title'] .= t('Inherit path from the page.');

      $form['inherit_path'] = array(
        '#type' => 'radios',
        '#options' => array(1 => t('Yes'), 0 => t('No')),
        '#default_value' => $this->get_option('inherit_path'),
        '#description' => t('If yes, all links generated by Views, such as more links, summary links, and exposed input links will go to the current page path, not the view, if the display has a path.'),
      );
      break;

    case 'argument_input':
      $form['#title'] .= t('Choose the data sources for contextual filters');
      $argument_input = $this->get_argument_input();

      $form['argument_input']['#tree'] = TRUE;

      foreach ($argument_input as $id => $argument) {
        $form['argument_input'][$id] = array(
          '#tree' => TRUE,
        );

        $safe = str_replace(array('][', '_', ' '), '-', $id);

        $form['argument_input'][$id]['type'] = array(
          '#type' => 'select',
          '#options' => array(
            'none' => t('No filter'),
            'url' => t('From URL'),
            //'context' => t('From context'),
            'fixed' => t('Fixed'),
            'user' => t('Input in block settings'),
            'wildcard' => t('Wildcard (*)'),
          ),
          '#attributes' => array('class' => array('argument-type-' . $safe)),
          '#title' => t('@arg source', array('@arg' => $argument['name'])),
          '#default_value' => $argument['type'],
        );
        $form['argument_input'][$id]['position'] = array(
          '#type' => 'select',
          '#title' => t('URL position'),
          '#description' => t('In the url http://example.com/foo/bar/baz, for example, foo would be in position 1, bar 2, and baz 3.'),
          '#default_value' => $argument['position'],
          '#options' => array(
            // Humans don't count from zero, adjust by one.
            0 => 1,
            1 => 2,
            2 => 3,
            3 => 4,
            4 => 5,
            5 => 6
          ),
          '#states' => array(
            'visible' => array(
              'select.argument-type-' . $safe => array('value' => 'url'),
            ),
          ),
        );
        /*
          $form['argument_input'][$id]['context'] = array(
            '#type' => 'select',
            '#title' => t('Required context'),
            '#description' => t('Which type of context to use.'),
            '#default_value' => $argument['context'],
            '#options' => array(), // @todo: Context options.
            '#states' => array(
              'visible' => array(
                'select.argument-type-' . $safe => array('value' => 'context'),
              ),
            ),
          );
          */

        $form['argument_input'][$id]['context_optional'] = array(
          '#type' => 'checkbox',
          '#title' => t('Context is optional'),
          '#description' => t('This context need not be present for the block to function. If you plan to use this, ensure that the contextual filter handler can handle empty values gracefully.'),
          '#default_value' => $argument['context_optional'],
          '#states' => array(
            'visible' => array(
              'select.argument-type-' . $safe => array('value' => 'context'),
            ),
          ),
        );

        $form['argument_input'][$id]['fixed'] = array(
          '#type' => 'textfield',
          '#title' => t('Fixed argument'),
          '#description' => t('This value will be set permanently as the filter value.'),
          '#default_value' => $argument['fixed'],
          '#states' => array(
            'visible' => array(
              'select.argument-type-' . $safe => array('value' => 'fixed'),
            ),
          ),
        );

        $form['argument_input'][$id]['label'] = array(
          '#type' => 'textfield',
          '#title' => t('Label'),
          '#description' => t('Label to apply to the filter when it is presented to the person configuring a layout.'),
          '#default_value' => empty($argument['label']) ? $argument['name'] : $argument['label'],
          '#states' => array(
            'visible' => array(
              'select.argument-type-' . $safe => array('value' => 'user'),
            ),
          ),
        );
      }

      if (empty($argument_input)) {
        $form['markup']['#markup'] = '<p>' . t('There are no contextual filters on this display.') . '</p>';
      }

      break;

    case 'exposed_form_options':
      $this->view->init_handlers();
      if (!$this->uses_exposed() && parent::uses_exposed()) {
        $form['exposed_form_options']['warning'] = array(
          '#weight' => -10,
          '#markup' => '<div class="messages warning">' . t('Exposed filters in block displays require "Use AJAX" to be set to work correctly.') . '</div>',
        );
      }
      break;

    case 'block_caching':
      $form['#title'] .= t('Block caching type');

      $form['block_caching'] = array(
        '#type' => 'radios',
        '#description' => t("This sets the default status for Backdrop's built-in block caching method; this requires that caching be turned on in block administration, and be careful because you have little control over when this cache is flushed."),
        '#options' => $this->block_caching_modes(),
        '#default_value' => $this->get_cache_type(),
      );
      break;
  }
}