1 views_handler_argument.inc views_handler_argument::options_form(&$form, &$form_state)

Build the options form.

Overrides views_handler::options_form

File

core/modules/views/handlers/views_handler_argument.inc, line 220
@todo.

Class

views_handler_argument
Base class for arguments.

Code

function options_form(&$form, &$form_state) {
  parent::options_form($form, $form_state);

  $argument_text = $this->view->display_handler->get_argument_text();

  $form['#pre_render'][] = 'views_ui_pre_render_move_argument_options';

  $form['description'] = array(
    '#markup' => $argument_text['description'],
    '#theme_wrappers' => array('container'),
    '#attributes' => array('class' => array('description')),
  );

  $form['no_argument'] = array(
    '#type' => 'fieldset',
    '#title' => $argument_text['filter value not present'],
  );
  // Everything in the fieldset is floated, so the last element needs to
  // clear those floats.
  $form['no_argument']['clearfix'] = array(
    '#weight' => 1000,
    '#markup' => '<div class="clearfix"></div>',
  );
  $form['default_action'] = array(
    '#type' => 'radios',
    '#process' => array('views_ui_process_container_radios'),
    '#default_value' => $this->options['default_action'],
    '#fieldset' => 'no_argument',
  );

  $form['exception'] = array(
    '#type' => 'fieldset',
    '#title' => t('Exceptions'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#fieldset' => 'no_argument',
  );
  $form['exception']['value'] = array(
    '#type' => 'textfield',
    '#title' => t('Exception value'),
    '#size' => 20,
    '#default_value' => $this->options['exception']['value'],
    '#description' => t('If this value is received, the filter will be ignored; i.e, "all values"'),
  );
  $form['exception']['title_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Override title'),
    '#default_value' => $this->options['exception']['title_enable'],
  );
  $form['exception']['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Override title'),
    '#title_display' => 'invisible',
    '#size' => 20,
    '#default_value' => $this->options['exception']['title'],
    '#description' => t('Override the view and other argument titles. Use "%1" for the first argument, "%2" for the second, etc.'),
    '#states' => array(
      'visible' => array(
        ':input[name="options[exception][title_enable]"]' => array('checked' => TRUE),
      ),
    ),
  );

  $options = array();
  $defaults = $this->default_actions();
  $validate_options = array();
  foreach ($defaults as $id => $info) {
    $options[$id] = $info['title'];
    if (empty($info['default only'])) {
      $validate_options[$id] = $info['title'];
    }
    if (!empty($info['form method'])) {
      $this->{$info['form method']}($form, $form_state);
    }
  }
  $form['default_action']['#options'] = $options;

  $form['argument_present'] = array(
    '#type' => 'fieldset',
    '#title' => $argument_text['filter value present'],
  );
  $form['title_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Override title'),
    '#default_value' => $this->options['title_enable'],
    '#fieldset' => 'argument_present',
  );
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Provide title'),
    '#title_display' => 'invisible',
    '#default_value' => $this->options['title'],
    '#description' => t('Override the view and other argument titles. Use "%1" for the first argument, "%2" for the second, etc.'),
    '#states' => array(
      'visible' => array(
        ':input[name="options[title_enable]"]' => array('checked' => TRUE),
      ),
    ),
    '#fieldset' => 'argument_present',
  );

  $form['breadcrumb_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Override breadcrumb'),
    '#default_value' => $this->options['breadcrumb_enable'],
    '#fieldset' => 'argument_present',
  );
  $form['breadcrumb'] = array(
    '#type' => 'textfield',
    '#title' => t('Provide breadcrumb'),
    '#title_display' => 'invisible',
    '#default_value' => $this->options['breadcrumb'],
    '#description' => t('Enter a breadcrumb name you would like to use. See "Title" for percent substitutions.'),
    '#states' => array(
      'visible' => array(
        ':input[name="options[breadcrumb_enable]"]' => array('checked' => TRUE),
      ),
    ),
    '#fieldset' => 'argument_present',
  );

  $form['specify_validation'] = array(
    '#type' => 'checkbox',
    '#title' => t('Specify validation criteria'),
    '#default_value' => $this->options['specify_validation'],
    '#fieldset' => 'argument_present',
  );

  $form['validate'] = array(
    '#type' => 'container',
    '#fieldset' => 'argument_present',
  );
  // @todo The mockup wanted to use "Validate using" here, but it doesn't
  // work well with many options (they'd need to be changed as well)
  $form['validate']['type'] = array(
    '#type' => 'select',
    '#title' => t('Validator'),
    '#default_value' => $this->options['validate']['type'],
    '#states' => array(
      'visible' => array(
        ':input[name="options[specify_validation]"]' => array('checked' => TRUE),
      ),
    ),
  );

  $validate_types = array('none' => t('- Basic validation -'));
  $plugins = views_fetch_plugin_data('argument validator');
  foreach ($plugins as $id => $info) {
    if (!empty($info['no ui'])) {
      continue;
    }

    $valid = TRUE;
    if (!empty($info['type'])) {
      $valid = FALSE;
      if (empty($this->definition['validate type'])) {
        continue;
      }
      foreach ((array) $info['type'] as $type) {
        if ($type == $this->definition['validate type']) {
          $valid = TRUE;
          break;
        }
      }
    }

    // If we decide this validator is ok, add it to the list.
    if ($valid) {
      $plugin = $this->get_plugin('argument validator', $id);
      if ($plugin) {
        if ($plugin->access() || $this->options['validate']['type'] == $id) {
          $form['validate']['options'][$id] = array(
            '#prefix' => '<div id="edit-options-validate-options-' . $id . '-wrapper">',
            '#suffix' => '</div>',
            '#type' => 'item',
            // Even if the plugin has no options add the key to the form_state.
            '#input' => TRUE, // trick it into checking input to make #process run
            '#states' => array(
              'visible' => array(
                ':input[name="options[specify_validation]"]' => array('checked' => TRUE),
                ':input[name="options[validate][type]"]' => array('value' => $id),
              ),
            ),
            '#id' => 'edit-options-validate-options-' . $id,
          );
          $plugin->options_form($form['validate']['options'][$id], $form_state);
          $validate_types[$id] = $info['title'];
        }
      }
    }
  }

  asort($validate_types);
  $form['validate']['type']['#options'] = $validate_types;

  $form['validate']['fail'] = array(
    '#type' => 'select',
    '#title' => t('Action to take if filter value does not validate'),
    '#default_value' => $this->options['validate']['fail'],
    '#options' => $validate_options,
    '#states' => array(
      'visible' => array(
        ':input[name="options[specify_validation]"]' => array('checked' => TRUE),
      ),
    ),
    '#fieldset' => 'argument_present',
  );
}