Question

I am trying to show taxonomy dropdown menu like

Term 1
--Term 2
--Term 3
Term 4

in an exposed filter taxonomy dropdown.

Right now children options are like

-Term 2
-Term 3

Is there any way to add this extra "-" in front of children terms in taxonomy dropdown menu?

Was it helpful?

Solution

You can use a form_alter to modify the exposed form. May be something like this.

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
 if ($form_id == 'views_exposed_form') {
   $category = $form['taxonomy_id']['#options'];
   foreach ($category as $tids => $value) {
      $options = $value->option;
      foreach ($options as $key => $value) {
       preg_match_all("/^\-.*/", $value, $matches);
       $match_found = $matches[0][0];
        // child elements only.
        if (!empty($match_found)) {
          $form['taxonomy_id']['#options'][$tids]->option[$key] = "-" . $match_found
        }
      }
    }
 }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top