By kcybulski on
I'm developing module what is using taxonomy vocabularies as fields name in node. Field name contain term ID (size_$term_id). Data are stored in table production (nid = int, vid = int, tid = int, size = int) key (nid, vid, tid), now I need to somehow pass this to node fields, but all what I was able to do, is to pass one value. Any help is greatly appreciated.
function production_form(&$node) {
$type = node_get_types('type', $node);
$term_get_vocs = taxonomy_get_vocabularies($type->type);
foreach($term_get_vocs as $term_get_voc) {
$terms = taxonomy_get_tree($term_get_voc->vid,0,-1,1);
foreach ($terms as $term) {
$tr = $term->name;
$tr_id = $term->tid;
$tr_size = 'size_'.$tr;
$tr_id_size = 'size_'.$tr_id;
$form["term_$tr_id"] = array(
'#type' => 'fieldset',
'#title' => t($tr),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$terms_2 = taxonomy_get_tree($term_get_voc->vid,$term->tid,-1,1);
foreach ($terms_2 as $term_2) {
$tr2 = $term_2->name;
$tr2_id = $term_2->tid;
$tr2_size = 'size_'.$tr2;
$tr2_id_size = 'size_'.$tr2_id;
$form["term_$tr_id"]["size_$tr2_id"] = array(
'#type' => 'textfield',
'#title' => t($tr2),
'#size' => 6,
'#default_value' => isset($node->$tr2_id_size) ? $node->$tr2_id_size : '',
'#maxlength' => 6,
'#required' => FALSE,
);
}
}
}
return $form;
}
function production_load($node) {
$type = node_get_types('type', $node);
$term_get_vocs = taxonomy_get_vocabularies($type->type);
foreach($term_get_vocs as $term_get_voc) {
$terms = taxonomy_get_tree($term_get_voc->vid,0,-1,1);
foreach ($terms as $term) {
$tr_id = $term->tid;
$terms_2 = taxonomy_get_tree($term_get_voc->vid,$term->tid,-1,1);
foreach ($terms_2 as $term_2) {
$tr2_id = $term_2->tid;
$tr2_id_size = 'size_'.$tr2_id;
$queryResult = (db_query("SELECT size as $tr2_id_size from {production} WHERE nid = %d and vid = %d and tid = %d", $node->nid, $node->vid, $tr2_id));
// What to add here ???
}
}
}
return $obj;
}
Comments
It's fixed, working version
It's fixed, working version below,