Hi, I'm stuck with something I can't figure out without getting more and more confused as I'm going deeper into the core code to understand.
I have an auto import module witch lets me create products nodes automatically (with ubercart indeed) using drupal execute.
It also creates the catalog taxonomy term and then associate it to the node.
It seems there is some $form cache between each page call, and I'm looking for a way to regenerate the form data that will use the drupal_execute so that it takes in count the new term.
Here's a simplified code of what I'm talking about
if (!$term_exists) {
// Here I create the term that will be used.
taxonomy_save_term($term_object);
$term_object = taxonomy_get_term_by_name($term_name);
$catalog_tid = $term_object[0]->tid;
}
// Launch node creation here.
$form_id = 'mynodetype_node_form';
$node->type = 'mynodetype';
$node->field_image_cache[0] = array(
'fid' => $file->fid,
'list' => 1,
'data' => array (
'alt' => $alt,
'title' => $title,
),
);
$form_state['values'] = array(
'title' => $title,
'status' => $publish_status,
'model' => $sku,
'taxonomy' => array (
$catalog_vid => array($catalog_tid),
),
'op' => t('Save'),
);
// Create and insert node into DB.
drupal_execute($form_id, $form_state, (object)$node);
Everything works just fine as long as the term has already been created.
It first call taxonomy_save_term() and then drupal_execute(), but with the execute the _form_validate() in form.inc pops the "An illegal choice has been detected" as its $elements['#options'] related to the terms contains all the terms but not the newly created one.
If I re-execute it, it works, because the term has already been created and $elements['#options'] does contain it.
As far as I could dig it's the drupal_alter('form', $data, $form_id); witch generates the $form array used to validate the node creation but without the new term. It is called by drupal_prepare_form($form_id, &$form, &$form_state) witch is called by drupal_execute($form_id, &$form_state)...
I'm calling for help as days are passing but I can't find a solution.
Comments
I would need some help
no ? no help ?
I have the last version of drupal.
I'm trying to understand why next after doing a taxonomy_save_term($term_object); the validation function of drupal_execute won't consider this new term and return an error "An illegal choice has been detected" like if the term was not saved. But it has been correctly saved, and if I launch it again it works as expected as the term already exists.
It seems to me that it is the form_builder function that won't actualize its $complete_form or $cache variables.
It must be a way to reload its data with all the new terms.
Any thoughts ?
I was wondering if you ever
I was wondering if you ever got this worked out. I ran into a similar issue with a recent project but in the end I didn't need to pull in new terms but during initial testing with a taxonomy field enabled (using Hierarchical Select) I ran into a lot of strange errors.
Even though I was not supplying terms in my test data random terms were being added during import which used drupal_execute() to create the nodes.
DrupalVoodoo
I'm having the exact same
I'm having the exact same problem.
Our client wants his new article nodes to create and link themselves to forum topics, combining node commentary with forum discussions.
He has categories for the articles, which are nodes themselves with a view of all nodes that are members of the category by nodereference to it attached to the bottom.
So I have some code that first checks to see if there is a forum that matches the category. If not, I create it by copying the category title and doing a drupal_execute.
Next the code forms up a proto-node and fills in the teaser and other text we want to put in the forum topic, such as the forum (category), then calls drupal_execute a second time to save that new forum topic node.
It always says 'illegal choice' if the taxonomy term, the forum the node is being assigned, was just created by the first part of the program.
I too would really like a solution to this problem.
All of my code is executed by hook_nodeapi on 'insert' and 'update'
Subscribing. Same problem
Subscribing. Same problem here.
And I solved my problem by directly inserting node and term ids into term_node table.