You are here

public function views_handler_filter_dynamic_fields::extra_options_form in Views Dynamic Fields 7

Provide an 'exclusion mode' option.

Overrides views_handler::extra_options_form

See also

\views\handler\views_handler::extra_options_form()

File

handlers/views_handler_filter_dynamic_fields.inc, line 104
Views dynamic fields filter handler.

Class

views_handler_filter_dynamic_fields
Simple filter to pick and choose the fields to show in the view.

Code

public function extra_options_form(&$form, &$form_state) {

  // Get all non-excluded fields.
  $view_fields = $this->view_fields;
  foreach ($view_fields as $field_name => $field) {
    if (empty($field['label'])) {
      $field_label = ucfirst($field['id']);
    }
    else {
      $field_label = $field['label'];
    }

    // Do not allow pre-configured excluded fields in the filter.
    if (isset($field['exclude']) && $field['exclude']) {
      $fields_excluded[$field_name] = $field_label;
    }
    else {
      $fields[$field_name] = $field_label;
    }
  }
  $form['description'] = array(
    '#type' => 'textfield',
    '#default_value' => $this->options['description'],
    '#title' => t('Exposed filter description'),
    '#description' => t('Change the default description for the exposed dynamic fields filter.'),
    '#size' => 40,
  );

  // Switch multi select mode vs single select.
  // @see http://drupal.org/node/1299806
  $form['checkboxes'] = array(
    '#type' => 'checkbox',
    '#default_value' => $this->options['checkboxes'],
    '#title' => t('List filters in checkboxes'),
    '#description' => t('If selected the fields will be listed as checkboxes (multi select mode), otherwise they will be listed in a select box (single select).'),
  );
  $form['filterable_fields'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Selectable Fields'),
    '#description' => t('Select the fields that you want to make available for filtering. Unchecked fields will not be filterable and will always show up in the view.'),
    '#options' => $fields,
    '#default_value' => $this->options['filterable_fields'],
  );
  $form['defaults_filterable_fields'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Default displayed fields'),
    '#description' => t('Select the fields that you want displayed by default in the view when no filtering is applied. Any explicitly unchecked fields in the list above will also be included as permanent fields. Leave empty to choose all fields.'),
    '#options' => $fields,
    '#default_value' => $this->options['defaults_filterable_fields'],
  );

  // Fields may been excluded from the view in field settings.
  if ($fields_excluded) {
    $form['filterable_fields_excluded'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Excluded fields'),
      '#options' => $fields_excluded,
      '#description' => t('You have configured these fields to be excluded from the view, hence they will not appear as filters.'),
      '#disabled' => TRUE,
    );
  }
  $form['reverse'] = array(
    '#type' => 'checkbox',
    '#default_value' => $this->options['reverse'],
    '#title' => t('Provide exclusion mode'),
    '#description' => t('Provide a checkbox to reverse the selection from inclusion to exclusion.'),
  );
  $form['reverse_label'] = array(
    '#type' => 'textfield',
    '#default_value' => $this->options['reverse_label'],
    '#title' => t('Label for exclusion fields options'),
    '#description' => t('Change the default label for the exclusion mode.'),
    '#size' => 40,
  );
}