You are here

function views_plugin_style_lineage_nested::options_form in Taxonomy Lineage 7

Same name and namespace in other branches
  1. 6 views_plugin_style_lineage_nested.inc \views_plugin_style_lineage_nested::options_form()

Render the given style.

Overrides views_plugin_style_list::options_form

File

plugins/views_plugin_style_lineage_nested.inc, line 28
Views style plugin that allows a view to be rendered as a nested list, based on Lineage's term hierarchy.

Class

views_plugin_style_lineage_nested
Implements views_plugin_style.

Code

function options_form(&$form, &$form_state) {

  // Assemble a list of Taxonomy Lineage fields.
  $nesting_options = array(
    '' => '[None]',
  );
  foreach ($this->display->handler
    ->get_handlers('field') as $field => $handler) {

    // Only include lineage fields.
    if ($handler->definition['handler'] == 'lineage_handler_field') {
      if ($label = $handler
        ->label()) {
        $nesting_options[$field] = $label;
      }
      else {
        $nesting_options[$field] = $handler
          ->ui_name();
      }
    }
  }

  // Assemble a list of Taxonomy filters and arguments
  $filter_options = array(
    '' => '[None]',
  );
  foreach ($this->display->handler
    ->get_handlers('filter') as $filter => $handler) {
    if ($this
      ->respond_to_filter($handler->definition['handler'])) {
      $filter_options['Filters']['f_' . $filter] = $handler
        ->ui_name();
    }
  }
  foreach ($this->display->handler
    ->get_handlers('argument') as $arg => $handler) {
    if ($this
      ->respond_to_filter($handler->definition['handler'])) {
      $filter_options['Arguments']['a_' . $arg] = $handler
        ->ui_name();
    }
  }
  $options = parent::options_form($form, $form_state);
  if (sizeof($nesting_options) > 1) {

    // one option is [None]
    $form['nesting'] = array(
      '#type' => 'select',
      '#title' => t('Nesting Field'),
      '#options' => $nesting_options,
      '#default_value' => $this->options['nesting'],
      '#description' => t('Select the Lineage field that will control the nesting.'),
    );
    $h_options = array(
      0 => t('default'),
    );
    for ($i = 1; $i <= 6; $i++) {
      $h_options[$i] = "<h{$i}>";
    }
    $default_header = $this->options['start_depth'] ? $this->options['start_depth'] : 0;
    $form['start_depth'] = array(
      '#type' => 'select',
      '#title' => 'Top-level header',
      '#options' => $h_options,
      '#default_value' => $default_header,
      '#description' => t('Header tag to use for the top-level term in the nesting.  If %default is selected, the plugin will choose the header level based on the properties of your view.', array(
        '%default' => $h_options[0],
      )),
    );
    if (sizeof($filter_options) > 1) {

      // one option is [None]
      $form['filter'] = array(
        '#type' => 'select',
        '#title' => 'Set top level with filter or argument',
        '#options' => $filter_options,
        '#default_value' => $this->options['filter'],
        '#description' => t("If selected, the nesting will begin with the term set by this argument or filter, and headers for parent terms will be hidden.  (Filters and arguments are listed in the same order as in your view.)  This feature is experimental."),
      );
    }
  }
}