Commit a19d7d80 authored by Ivan's avatar Ivan Committed by Damien McKenna
Browse files

Issue #1695658 by Chi, aloyr, Simon Georges, jzavrl, DamienMcKenna, Ante890,...

Issue #1695658 by Chi, aloyr, Simon Georges, jzavrl, DamienMcKenna, Ante890, semiaddict, jespermb, millerrs, glynster, philipz, dawehner, -Mania-, rositis@gmail.com, Lang Wu Jane, nimek, travisc, dmitryl, coconnor: Support optgroups for taxonomy selection list.
parent 5c44b7f1
Loading
Loading
Loading
Loading
+25 −9
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ class views_handler_filter_term_node_tid extends views_handler_filter_many_to_on
    $options['vocabulary'] = array('default' => 0);
    $options['hierarchy'] = array('default' => 0);
    $options['error_message'] = array('default' => TRUE, 'bool' => TRUE);
    $options['optgroups'] = array('default' => 0);

    return $options;
  }
@@ -106,6 +107,14 @@ class views_handler_filter_term_node_tid extends views_handler_filter_many_to_on
      '#default_value' => !empty($this->options['hierarchy']),
      '#dependency' => array('radio:options[type]' => array('select')),
    );

    $form['optgroups'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show groups in dropdown'),
      '#default_value' => !empty($this->options['optgroups']),
      '#dependency' => array('radio:options[type]' => array('select')),
    );

  }

  /**
@@ -145,15 +154,22 @@ class views_handler_filter_term_node_tid extends views_handler_filter_many_to_on
    else {
      if (!empty($this->options['hierarchy']) && $this->options['limit']) {
        $tree = taxonomy_get_tree($vocabulary->vid, 0, NULL, TRUE);
        $options = array();

        if ($tree) {
          // Translation system needs full entity objects, so we have access to
          // label.
        if (!empty($tree)) {
          if (!empty($this->options['optgroups'])) {
            foreach ($tree as $term) {
            $choice = new stdClass();
            $choice->option = array($term->tid => str_repeat('-', $term->depth) . entity_label('taxonomy_term', $term));
            $options[] = $choice;
              $term_name = entity_label('taxonomy_term', $term);
              if ($term->parents[0] == 0) {
                $parent_name = $term_name;
              }
              else {
                $options[$parent_name][$term->tid] = str_repeat('-', $term->depth - 1) . $term_name;
              }
            }
          }
          else {
            foreach ($tree as $term) {
              $options[$term->tid] = str_repeat('-', $term->depth) . entity_label('taxonomy_term', $term);
            }
          }
        }
      }