You are here

API.txt in Hierarchical Select 5

Same filename and directory in other branches
  1. 5.3 API.txt
  2. 5.2 API.txt
  3. 6.3 API.txt
  4. 7.3 API.txt
Hooks
-----
1) hook_hierarchical_select_render($hsid, $selection, $params);

This hook is called whenever the user makes a selection. It should return a
new set of rendered selects. See hierarchical_select_taxonomy.inc for an
example.

2) hook_hierarchial_select_form_alter($form_id, &$form);

This hook is absolutely optional. The sole reason for its existence, is to
allow easy altering of Drupal core forms to use the hierarchical_select form
item. To render the actual HTML, there's a helper function available:
  hierarchical_select_render_selects($hsid, $selects);


Form API usage
--------------
And last, but not least, you have to make sure your form item is using the
"hierarchical_select" form element type:

  $form['tid'] = array(
    '#type' => 'hierarchical_select',
    '#title' => t('Select the tag you wish to use.'),
    '#options' => $options, // Contains an array of tid - term name pairs.
    '#hierarchical_select_settings' => array(
      'module' => 'taxonomy',
      'params' => array(
        'vid' => $vid,
      ),
    ),
    '#default_value' => '83',
  ); 

A quick scan learns us that:
1) We've set the #type property to "hierarchical_select" instead of "select".
2) There's a new property: #hierarchical_select_settings. This must be an
array.
An obligated key/value pair in this array is "module". This will be passed
through in the AHAH requests, to let the hierarchical_select module know which
module's rendering function should be used.
The other key/value pair in this array is optional: "params". This must again
be an array. But this time, you can specify whatever other parameters you have
to know to be able to render the new selects. In the case of taxonomy, this is
the vocabulary id (vid). In case of content_taxonomy, there's an additional
parameter: the depth.
The "params" array is also passed through in every AHAH request.

File

API.txt
View source
  1. Hooks
  2. -----
  3. 1) hook_hierarchical_select_render($hsid, $selection, $params);
  4. This hook is called whenever the user makes a selection. It should return a
  5. new set of rendered selects. See hierarchical_select_taxonomy.inc for an
  6. example.
  7. 2) hook_hierarchial_select_form_alter($form_id, &$form);
  8. This hook is absolutely optional. The sole reason for its existence, is to
  9. allow easy altering of Drupal core forms to use the hierarchical_select form
  10. item. To render the actual HTML, there's a helper function available:
  11. hierarchical_select_render_selects($hsid, $selects);
  12. Form API usage
  13. --------------
  14. And last, but not least, you have to make sure your form item is using the
  15. "hierarchical_select" form element type:
  16. $form['tid'] = array(
  17. '#type' => 'hierarchical_select',
  18. '#title' => t('Select the tag you wish to use.'),
  19. '#options' => $options, // Contains an array of tid - term name pairs.
  20. '#hierarchical_select_settings' => array(
  21. 'module' => 'taxonomy',
  22. 'params' => array(
  23. 'vid' => $vid,
  24. ),
  25. ),
  26. '#default_value' => '83',
  27. );
  28. A quick scan learns us that:
  29. 1) We've set the #type property to "hierarchical_select" instead of "select".
  30. 2) There's a new property: #hierarchical_select_settings. This must be an
  31. array.
  32. An obligated key/value pair in this array is "module". This will be passed
  33. through in the AHAH requests, to let the hierarchical_select module know which
  34. module's rendering function should be used.
  35. The other key/value pair in this array is optional: "params". This must again
  36. be an array. But this time, you can specify whatever other parameters you have
  37. to know to be able to render the new selects. In the case of taxonomy, this is
  38. the vocabulary id (vid). In case of content_taxonomy, there's an additional
  39. parameter: the depth.
  40. The "params" array is also passed through in every AHAH request.