Я немного смущен. Я создал простую форму с одним текстовым полем и кнопкой отправки. Теперь я хочу добавить выбор/опцию выпадающее поле условий таксономии, с помощью taxonomy_get_vocabularies () функция.
$vocabularies = taxonomy_get_vocabularies('my_type');
Мой вопрос состоит в том, как я получаю список словаря на форму "Drupal путь". Путем Drupal определяет форму, кажутся довольно твердыми. Также, как я мог сделать этот conditionl, сказать относительно существования соответствующих условий таксономии.
function my_form_name($form_state) {
// A Short question.
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Question'),
'#default_value' => $node->title,
'#required' => TRUE,
'#weight' => 1,
'#description' => t('A text box goes here '),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('submit'),
'#weight' => 7,
);
return $form;
Я делаю нечто подобное в специальной форме и обнаружил, что это намного проще используйте taxonomy_get_tree со словарным кодом в качестве аргумента функции. См. Ниже:
//get the list of locations from taxonomy to use in the dropdown
$dropdown_source = taxonomy_get_tree(2);
$dropdown_array = array('0' => '--none--');
foreach ($dropdown_source as $item) {
$key = $item->tid;
$value = $item->name;
$dropdown_array[$key] = $value;
}
//location filter dropdown
$form['filterset']['locationfilter'] = array(
'#weight' => '1',
'#key_type' => 'associative',
'#multiple_toggle' => '1',
'#type' => 'select',
'#options' => $dropdown_array,
'#title' => 'Filter by location',
);
unset($dropdown_array);
спасибо за быстрый ответ! Думаю, у меня получилось вот так.
$form['limiter'] = array(
'#type' => 'select',
'#title' => t('Choose a value'),
'#id' => 'limiter',
'#options' => get_faq_terms(),
);
function get_faq_terms() {
// get the vid value from vocabulary_node_types file
$result = db_query("SELECT * FROM vocabulary_node_types WHERE type = 'my_type' ");
$node = db_fetch_object($result) ;
$vid = $node->vid ;
// get corresponding term names from term_data file
$items = array();
$terms = taxonomy_get_tree($vid);
foreach ( $terms as $term ) {
$count = taxonomy_term_count_nodes($term->tid);
if ($count) {
$items[$term->tid] = $term->name;
}
}
Узнайте, как это сделать, в файле taxonomy.admin.inc модуля таксономии
/**
* Form builder to list and manage vocabularies.
*
* @ingroup forms
* @see taxonomy_overview_vocabularies_submit()
* @see theme_taxonomy_overview_vocabularies()
*/
function taxonomy_overview_vocabularies() {
$vocabularies = taxonomy_get_vocabularies();
$form = array('#tree' => TRUE);
foreach ($vocabularies as $vocabulary) {
...