Mostrar en un Select las opciones obtenidas de un Vocabulario Drupal 7

//get the list of locations from taxonomy to use in the dropdown
        $dropdown_source = taxonomy_get_tree(122, $parent = 0, $max_depth = null, $load_entities = FALSE);
//En la tabla: TAXONOMY_VOCABULARY, puede ver el vid que debes poner (122 en este ejemplo)
        print_r($dropdown_source);
        $dropdown_array = array('0' => '--none--');
        foreach ($dropdown_source as $item) {
            $key = $item->tid;
          //Condición reaizada para mostrarlos asi:
             x
             --x1
             --x2
            y

        if ($item->depth == 0){
                $value = $item->name;
            }else{
                $value = '--'.$item->name;
            }
            $dropdown_array[$key] = $value;
        }
       
    $form = array();
    $form['area'] = array(
            '#key_type' => 'associative',
            '#multiple_toggle' => '1',
            '#type' => 'select',
            '#options' => $dropdown_array,
            '#title' => 'Area',
        );
return $form;

Comentarios

Entradas populares