Hello

I'm creating a custom module and I want to use the Taxonomy Term Reference Tree Widget in a drupal_get_from page. How can I use this?

My idea is following code:

$form['mymodule_customfield'] = array(
  '#type' => 'checkbox_tree',
  '#title' => t('Custom title'),
  '#vocabulary' => 2,
  '#max_choices' => -1,
  ...
);

Best regards
mijo

Comments

drupal.ninja03’s picture

I also need this information. Hope someone can help.
Thanks.

saemie’s picture

It would still be good to know this.

pratip.ghosh’s picture

Still no update on this? How do I render a term reference tree field in my template page?

-- Pratip Ghosh

Petrica’s picture

Inspired from here

  $term_reference_tree_path = drupal_get_path('module', 'term_reference_tree');
  $form['tree'] = array(
      '#title' => t('Tree'),
      '#type' => 'checkbox_tree',
      '#max_choices' => 999,
      '#max_depth' => 999,
      '#field_name' => 'custom_name',
      '#leaves_only' => 1,
      '#start_minimized' => TRUE,
      '#depth' => 0,
      '#vocabulary' => taxonomy_vocabulary_load(3),
      '#parent_tid' => 0,
      '#value_key' => 'tid',
      '#select_parents' => TRUE,
      '#attached' => array(
          'js' => array($term_reference_tree_path . '/term_reference_tree.js'),
          'css' => array($term_reference_tree_path . '/term_reference_tree.css')
      ),
      '#attributes' => array('class' => array('field-widget-term-reference-tree')),
      '#element_validate' => array('_term_reference_tree_widget_validate'),
      '#value' => array(),
      '#filter_view' => '',
      '#token_display' => ''
    );
rakesh.gectcr’s picture

Yhooo! Petrica..

Your code works ....

---
Kind regards,

Thank you,
Rakesh James

PascalMortier’s picture

I see the taxonomy tree on my form. But when I post the form, I have no values in my _form_submit function.

mahyarsbt’s picture

Hi,

Please help me to use in Drupal 9 programmatically in form API