Hi all, For the node_import module which tries to import a whole set of nodes from a CSV file, I have the following problem: how does one validate a "$node" before "node_save()"ing it? Let me explain: In 4.6 we had the "node_validate($node)" function which validates the node (calling "hook_validate()" and "hook_nodeapi('validate')" as needed). If this was succesful (no "form_get_errors()"), then we could safely "node_save($node)" it. Now, in 4.7, most (if not all) validation is done using the form API, in things like "#validate" and "#required". For example, "story.module" requires that the title is not empty. It does that by setting a "#required" on the title-textfield. If I do: $node = (object) array('type' => 'story', 'uid' => 42, 'title' => ''); the node will pass "node_validate($node)", but this is because the validation inside "$form" was not run! So my questions are: - how does one validate a node programmatically *correctly*? - what is the point of the "node_validate()" function and the hooks if it doesn't actually *validate* the node at all? At least rename it to "node_noop()" so things are clear. - really, why have "node_validate()" at all? Does anyone do anything usefull in it? - and the real question: how does the following sequence of 4.6 translate into 4.7: $node->type = 'story'; $node->uid = 1; $node->title = ''; // invalid empty title! $node->body = ''; // invalid empty body! $node = node_validate($node); // if life was only that // that easy in 4.7... if (form_get_errors()) { // we detected the error... do something unset($GLOBALS['form']); // note: we unset $GLOBALS['form'] so the next time we // try this trick, form_get_errors() return the errors // of the last run and not of the previous. // If something like this would be possible in 4.7 it // would be great, but form_set_error() in 4.7 saves the // errors in a static variable inside form_set_error() // instead of in $GLOBALS['form']. I see no way to unset // that... $output .= node_view($node); } else { // no errors? hmm, great, save it... quickly before // "they" introduce something else that breaks // "common sense". Really: why call something // foobar_validate() if it doesn't validate anything // at all... Am I alone in this? I guess so. node_save($node); } Anyway, I have a solution, but that is so hackerish that I hope others know "The Right Solution(tm)". Thanks, Robrecht
Robrecht - You can take a look at my quotes.module. It can import several quotes through a single node submission form. Although the concept is a bit different from what you are doing, it does have to individually validate and submit each quote. You might be able to get some hints from it...or give me some hints if you see problems with my code! ;-) - Jim On 6 Jun 2006, at 20:15, Robrecht Jacques wrote:
Hi all,
For the node_import module which tries to import a whole set of nodes from a CSV file, I have the following problem: how does one validate a "$node" before "node_save()"ing it?
Let me explain:
In 4.6 we had the "node_validate($node)" function which validates the node (calling "hook_validate()" and "hook_nodeapi('validate')" as needed). If this was succesful (no "form_get_errors()"), then we could safely "node_save($node)" it.
Now, in 4.7, most (if not all) validation is done using the form API, in things like "#validate" and "#required". For example, "story.module" requires that the title is not empty. It does that by setting a "#required" on the title-textfield. If I do: $node = (object) array('type' => 'story', 'uid' => 42, 'title' => ''); the node will pass "node_validate($node)", but this is because the validation inside "$form" was not run!
So my questions are: - how does one validate a node programmatically *correctly*? - what is the point of the "node_validate()" function and the hooks if it doesn't actually *validate* the node at all? At least rename it to "node_noop()" so things are clear. - really, why have "node_validate()" at all? Does anyone do anything usefull in it? - and the real question: how does the following sequence of 4.6 translate into 4.7: $node->type = 'story'; $node->uid = 1; $node->title = ''; // invalid empty title! $node->body = ''; // invalid empty body!
$node = node_validate($node); // if life was only that // that easy in 4.7...
if (form_get_errors()) { // we detected the error... do something unset($GLOBALS['form']);
// note: we unset $GLOBALS['form'] so the next time we // try this trick, form_get_errors() return the errors // of the last run and not of the previous. // If something like this would be possible in 4.7 it // would be great, but form_set_error() in 4.7 saves the // errors in a static variable inside form_set_error() // instead of in $GLOBALS['form']. I see no way to unset // that... $output .= node_view($node); } else { // no errors? hmm, great, save it... quickly before // "they" introduce something else that breaks // "common sense". Really: why call something // foobar_validate() if it doesn't validate anything // at all... Am I alone in this? I guess so. node_save($node); }
Anyway, I have a solution, but that is so hackerish that I hope others know "The Right Solution(tm)".
Thanks, Robrecht
On 6/7/06, Jim Riggs <drupal-lists@jimandlissa.com> wrote:
You can take a look at my quotes.module. It can import several quotes through a single node submission form. Although the concept is a bit different from what you are doing, it does have to individually validate and submit each quote. You might be able to get some hints from it...or give me some hints if you see problems with my code! ;-)
The problem with your importing code is exactly what I was pointing out. Suppose I attach a required taxonomy to the "quotes" content type. You don't set it. You don't validate it. Still the node is created. Or if I use hook_form_alter() to add a "#required" to the title textfield so it must be non-empty... you'll happily save the node without the title set. You also bail out creating quotes from the first error you encounter while I would like to import the next rows too. I may have misread the code. Now for your specific case, this may be ok, but for a generic node_import it is not. Robrecht
On 7 Jun, 2006, at 3:24, Robrecht Jacques wrote:
On 6/7/06, Jim Riggs <drupal-lists@jimandlissa.com> wrote: You can take a look at my quotes.module. It can import several quotes through a single node submission form. Although the concept is a bit different from what you are doing, it does have to individually validate and submit each quote. You might be able to get some hints from it...or give me some hints if you see problems with my code! ;-)
The problem with your importing code is exactly what I was pointing out. Suppose I attach a required taxonomy to the "quotes" content type. You don't set it. You don't validate it. Still the node is created. Or if I use hook_form_alter() to add a "#required" to the title textfield so it must be non-empty... you'll happily save the node without the title set.
No, I don't set the required taxonomy, but it will be set if required. The user has to set it. They are presented with a complete node/add form, including taxonomy selection. It's just that in my case they can import many items via the body textarea. So, the required taxonomy is indeed set and validated when node_validate() is called for each imported item in quotes_submit(). Same for the title. If it's required, it will have to be set, because it is validated before any submit() call can take place. Again, conceptually what I am doing may be different from what you are doing. My users are presented with the node/add form. I use the "template" node object that was submitted as a base for each of the individual nodes I create, so my import gets most of the validation and node-submission stuff for free. The key is in the foreach loop in quotes_submit() where I take this template node that has been created and set the body, teaser, author, etc., for this individual node, validate it, submit it, and save it. This may be similar to what you need to do; maybe not.
You also bail out creating quotes from the first error you encounter while I would like to import the next rows too.
Yeah. That was just a design decision, though. I could have easily continued the import.
On 6/7/06, Jim Riggs <drupal-lists@jimandlissa.com> wrote:
On 7 Jun, 2006, at 3:24, Robrecht Jacques wrote: No, I don't set the required taxonomy, but it will be set if required. The user has to set it. They are presented with a complete node/add form, including taxonomy selection. It's just that in my case they can import many items via the body textarea.
... Ah, ok. Only read through the code quickly. So the node/add form already does this validation for you and you don't need to do that validation again. Then indeed a simple "node_validate()" will work. But in my case there is no node/add form that the user submitted but still i want this form validation to be done somehow.
You also bail out creating quotes from the first error you
encounter while I would like to import the next rows too.
Yeah. That was just a design decision, though. I could have easily continued the import.
How? You check form_get_errors(). If this returns something, you know the node_valiate() has failed. But how do you clear out the errors you've already got before the next node_validate() you do in the foreach loop? The errors stay inside a static array in form_set_error() and can not be cleared at all. So the import you try after one with errors will also have some form_get_errors()... in fact, the same ones as the first row with errors. Your code works, but unfortunately I can't use it as I need to do the "user presses submit on the node/add form" programmatically too. Thx, Robrecht
- how does one validate a node programmatically *correctly*? - what is the point of the "node_validate()" function and the hooks if it doesn't actually *validate* the node at all? At least rename it to "node_noop()" so things are clear. - really, why have "node_validate()" at all? Does anyone do anything usefull in it?
good question. unfortunately, 4.7 is a bit of an intermediate solution which makes this hard. the conceptual way to do is is to programtically "submit" the story form. In 4.7, this amounts to populating the proper $_POST variables like 'type' and 'title' and so on and then building the node form by calling the right functions and then calling drupal_get_form(). the node form is the most complex of all our forms so i'm not sure this works right. form api 2.0 will be focused on making things like this easy again. -moshe
On 6/7/06, Moshe Weitzman <weitzman@tejasa.com> wrote:
unfortunately, 4.7 is a bit of an intermediate solution which makes this hard. the conceptual way to do is is to programtically "submit" the story form. In 4.7, this amounts to populating the proper $_POST variables like 'type' and 'title' and so on and then building the node form by calling the right functions and then calling drupal_get_form(). the node form is the most complex of all our forms so i'm not sure this works right.
form api 2.0 will be focused on making things like this easy again.
Indeed. I've been chatting to Adrian about FAPI 2.0, and the vision is for there to be a separation between 'user-facing forms' and 'data definitions', and for the data definition system to handle things like validation. So an import module, for example, could work with the definition directly, rather than going 'through' a form. This is closely tied in to the import / export API that I'm working on, as my Summer of Code project. @Robrecht: have you heard about this project? I have looked into your node_import module, and I would love to hear any feedback that you may have about what you'd like to see in an import / export API. Your module has already given me plenty of ideas for what should be in such an API. Cheers, Jaza.
On 6/7/06, Jeremy Epstein <jazepstein@gmail.com> wrote:
Indeed. I've been chatting to Adrian about FAPI 2.0, and the vision is for there to be a separation between 'user-facing forms' and 'data definitions', and for the data definition system to handle things like validation. So an import module, for example, could work with the definition directly, rather than going 'through' a form. This is closely tied in to the import / export API that I'm working on, as my Summer of Code project.
@Robrecht: have you heard about this project? I have looked into your node_import module, and I would love to hear any feedback that you may have about what you'd like to see in an import / export API. Your module has already given me plenty of ideas for what should be in such an API.
Is the code or specs somewhere? I've read your SOC proposal just now, and if it get's implemented right, node_import will only be a few lines... so I'm very much interested :-) Robrecht
On 6/7/06, Moshe Weitzman <weitzman@tejasa.com> wrote:
- how does one validate a node programmatically *correctly*? - what is the point of the "node_validate()" function and the hooks if it doesn't actually *validate* the node at all? At least rename it to "node_noop()" so things are clear. - really, why have "node_validate()" at all? Does anyone do anything usefull in it?
good question.
unfortunately, 4.7 is a bit of an intermediate solution which makes this hard. the conceptual way to do is is to programtically "submit" the story form. In 4.7, this amounts to populating the proper $_POST variables like 'type' and 'title' and so on and then building the node form by calling the right functions and then calling drupal_get_form(). the node form is the most complex of all our forms so i'm not sure this works right.
OK. This is more or less the path I'm following: getting the node-form array passing it the $node object. This will set the #default_value everywhere. Then I copy the #default_value values into #value and set #need_validation. Then I do a drupal_form_validate(). Problem here is: form_set_error() keeps a static variable of the errors on the form. So if you want to import *two* nodes, the errors of the first run will still be present in the second run with no way of clearing them. form api 2.0 will be focused on making things like this easy again. I'm not critizing form api 1.0. I think it works great in most cases. But not in mine :-( Seperating data (with validation / submit) and the actual form seems like the way forward. Robrecht
On 07 Jun 2006, at 5:07 AM, Moshe Weitzman wrote:
unfortunately, 4.7 is a bit of an intermediate solution which makes this hard. the conceptual way to do is is to programtically "submit" the story form. In 4.7, this amounts to populating the proper $_POST variables like 'type' and 'title' and so on and then building the node form by calling the right functions and then calling drupal_get_form(). the node form is the most complex of all our forms so i'm not sure this works right.
form api 2.0 will be focused on making things like this easy again.
My goal with FAPI 2.0 is something like the following : $node = drupal_request_model('node/add/event'); // provides a pre- populated post request. $node['title'] = 'something'; $node['body'] = 'something else goes here'; $result = drupal_submit_request('node/add/event', $node); // triggers all the fapi validation and submission code. But for all forms. -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
With no claim that it's the Right Way(c) function syndicator_item_to_node($item_id = NULL) {
global $user; if (is_null($item_id)) { $iid = arg(2); if (isset($iid)) { $item = db_fetch_object(db_query(SYNDICATOR_PROMOTE_TO_NODE_QUERY, $iid)); } } else if (is_numeric($item_id)) { $item = db_fetch_object(db_query(SYNDICATOR_PROMOTE_TO_NODE_QUERY, $item_id)); } if (isset($item)) { $node = new stdClass(); $node->is_new = true; $item->description = check_markup($item->description, $node->filter); $node->created = time(); $node->date = format_date($item->timestamp, 'custom', 'Y-m-d H:i:s O'); $node->type = variable_get('syndicator_publish_node_type', 'none'); $node->title = $item->title; $node->filter = variable_get('filter_default_format', FILTER_FORMAT_DEFAULT); $node->body = theme('syndicator_published_content', $item); $node->teaser = node_teaser(theme('syndicator_published_content', $item), variable_get('filter_default_format', FILTER_FORMAT_DEFAULT)); // might be unnecessary
$node_options = variable_get('node_options_' . $node->type, array()); $node->comment = variable_get('comment_' . $node->type, 2); unset($node->nid); $node = node_submit($node); $node->uid = $user->uid ? $user->uid : 1; module_invoke('node', 'save', $node); } }
On 6/6/06, Robrecht Jacques <robrechtj+drupal@gmail.com> wrote:
- and the real question: how does the following sequence of 4.6 translate into 4.7:
$node->type = 'story'; $node->uid = 1; $node->title = ''; // invalid empty title! $node->body = ''; // invalid empty body!
$node = node_validate($node); // if life was only that
// that easy in 4.7...
if (form_get_errors()) { // we detected the error... do something unset($GLOBALS['form']);
// note: we unset $GLOBALS['form'] so the next time we
// try this trick, form_get_errors() return the errors // of the last run and not of the previous. // If something like this would be possible in 4.7 it // would be great, but form_set_error() in 4.7 saves the
// errors in a static variable inside form_set_error() // instead of in $GLOBALS['form']. I see no way to unset // that... $output .= node_view($node); } else { // no errors? hmm, great, save it... quickly before
// "they" introduce something else that breaks // "common sense". Really: why call something // foobar_validate() if it doesn't validate anything // at all... Am I alone in this? I guess so.
node_save($node); }
On 6/7/06, Earl Dunovant <prometheus6@gmail.com> wrote:
With no claim that it's the Right Way(c)
Again, no validation at all. I know how to create a node programmatically. But this way, you can't be sure it is valid. Thanks anyway, Robrecht function syndicator_item_to_node($item_id = NULL) {
global $user; if (is_null($item_id)) { $iid = arg(2); if (isset($iid)) { $item = db_fetch_object(db_query(SYNDICATOR_PROMOTE_TO_NODE_QUERY, $iid)); } } else if (is_numeric($item_id)) { $item = db_fetch_object(db_query(SYNDICATOR_PROMOTE_TO_NODE_QUERY, $item_id)); } if (isset($item)) { $node = new stdClass(); $node->is_new = true; $item->description = check_markup($item->description, $node->filter); $node->created = time(); $node->date = format_date($item->timestamp, 'custom', 'Y-m-d H:i:s O'); $node->type = variable_get('syndicator_publish_node_type', 'none'); $node->title = $item->title; $node->filter = variable_get('filter_default_format', FILTER_FORMAT_DEFAULT); $node->body = theme('syndicator_published_content', $item); $node->teaser = node_teaser(theme('syndicator_published_content', $item), variable_get('filter_default_format', FILTER_FORMAT_DEFAULT)); // might be unnecessary
$node_options = variable_get('node_options_' . $node->type, array()); $node->comment = variable_get('comment_' . $node->type, 2); unset($node->nid); $node = node_submit($node); $node->uid = $user->uid ? $user->uid : 1; module_invoke('node', 'save', $node); } }
On 6/6/06, Robrecht Jacques <robrechtj+drupal@gmail.com> wrote:
- and the real question: how does the following sequence of 4.6translate into 4.7:
$node->type = 'story'; $node->uid = 1; $node->title = ''; // invalid empty title! $node->body = ''; // invalid empty body!
$node = node_validate($node); // if life was only that
// that easy in 4.7...
if (form_get_errors()) { // we detected the error... do something unset($GLOBALS['form']);
// note: we unset $GLOBALS['form'] so the next time we
// try this trick, form_get_errors() return the errors // of the last run and not of the previous. // If something like this would be possible in 4.7 it // would be great, but form_set_error() in 4.7 saves the
// errors in a static variable inside form_set_error() // instead of in $GLOBALS['form']. I see no way to unset // that... $output .= node_view($node); } else { // no errors? hmm, great, save it... quickly before
// "they" introduce something else that breaks // "common sense". Really: why call something // foobar_validate() if it doesn't validate anything // at all... Am I alone in this? I guess so.
node_save($node); }
Question: since node_validate() really does validate your new node (being a standard story node), why can't you use it? On 6/7/06, Robrecht Jacques <robrechtj+drupal@gmail.com> wrote:
On 6/7/06, Earl Dunovant <prometheus6@gmail.com> wrote:
With no claim that it's the Right Way(c)
Again, no validation at all.
I know how to create a node programmatically. But this way, you can't be sure it is valid.
Thanks anyway, Robrecht
function syndicator_item_to_node($item_id = NULL) {
global $user; if (is_null($item_id)) { $iid = arg(2); if (isset($iid)) { $item = db_fetch_object(db_query(SYNDICATOR_PROMOTE_TO_NODE_QUERY, $iid)); } } else if (is_numeric($item_id)) { $item = db_fetch_object(db_query(SYNDICATOR_PROMOTE_TO_NODE_QUERY, $item_id)); } if (isset($item)) { $node = new stdClass(); $node->is_new = true; $item->description = check_markup($item->description, $node->filter); $node->created = time(); $node->date = format_date($item->timestamp, 'custom', 'Y-m-d H:i:s O'); $node->type = variable_get('syndicator_publish_node_type', 'none'); $node->title = $item->title; $node->filter = variable_get('filter_default_format', FILTER_FORMAT_DEFAULT); $node->body = theme('syndicator_published_content', $item); $node->teaser = node_teaser(theme('syndicator_published_content', $item), variable_get('filter_default_format', FILTER_FORMAT_DEFAULT)); // might be unnecessary
$node_options = variable_get('node_options_' . $node->type, array()); $node->comment = variable_get('comment_' . $node->type, 2); unset($node->nid); $node = node_submit($node); $node->uid = $user->uid ? $user->uid : 1; module_invoke('node', 'save', $node); } }
On 6/6/06, Robrecht Jacques <robrechtj+drupal@gmail.com> wrote:
- and the real question: how does the following sequence of 4.6translate into 4.7:
$node->type = 'story'; $node->uid = 1; $node->title = ''; // invalid empty title! $node->body = ''; // invalid empty body!
$node = node_validate($node); // if life was only that
// that easy in 4.7...
if (form_get_errors()) { // we detected the error... do something unset($GLOBALS['form']);
// note: we unset $GLOBALS['form'] so the next time we
// try this trick, form_get_errors() return the errors // of the last run and not of the previous. // If something like this would be possible in 4.7 it // would be great, but form_set_error() in
4.7 saves the
// errors in a static variable inside form_set_error() // instead of in $GLOBALS['form']. I see no way to unset // that... $output .= node_view($node); } else { // no errors? hmm, great, save it... quickly before
// "they" introduce something else that breaks // "common sense". Really: why call something // foobar_validate() if it doesn't validate anything // at all... Am I alone in this? I guess so.
node_save($node); }
Despite what the name implies, node_validate() does not validate the node at all. Or at least not completely. Try to submit a story node using the UI form. If you don't enter a title, you'll get an error (Title is required). But programmatically : $node->type = 'story'; $node->uid = 1; $node->title = ''; // invalid empty title! $node->body = ''; // invalid empty body! // node_validate() does not check the emptiness of title or body // like the UI does, so this validation will work... but shouldn't. node_validate($node); if (form_get_errors()) { // I would expect to arrive here as the node was not valid (no // non-empty title or body set). } else { // But instead, I arrive here and the node is saved without // trouble. If I go to the edit page of the new node, I'll get // the form_errors again. node_save($node); } This may be called a bug. Or at least rename node_validate() to node_doesn't_validate(). Robrecht On 6/7/06, Earl Dunovant <prometheus6@gmail.com> wrote:
Question: since node_validate() really does validate your new node (being a standard story node), why can't you use it?
On 6/7/06, Robrecht Jacques < robrechtj+drupal@gmail.com> wrote:
On 6/7/06, Earl Dunovant <prometheus6@gmail.com> wrote:
With no claim that it's the Right Way(c)
Again, no validation at all.
I know how to create a node programmatically. But this way, you can't be sure it is valid.
Thanks anyway, Robrecht
function syndicator_item_to_node($item_id = NULL) {
global $user; if (is_null($item_id)) { $iid = arg(2); if (isset($iid)) { $item = db_fetch_object(db_query(SYNDICATOR_PROMOTE_TO_NODE_QUERY, $iid)); } } else if (is_numeric($item_id)) { $item = db_fetch_object(db_query(SYNDICATOR_PROMOTE_TO_NODE_QUERY, $item_id)); } if (isset($item)) { $node = new stdClass(); $node->is_new = true; $item->description = check_markup($item->description, $node->filter); $node->created = time(); $node->date = format_date($item->timestamp, 'custom', 'Y-m-d H:i:s O'); $node->type = variable_get('syndicator_publish_node_type', 'none'); $node->title = $item->title; $node->filter = variable_get('filter_default_format', FILTER_FORMAT_DEFAULT); $node->body = theme('syndicator_published_content', $item); $node->teaser = node_teaser(theme('syndicator_published_content', $item), variable_get('filter_default_format', FILTER_FORMAT_DEFAULT)); // might be unnecessary
$node_options = variable_get('node_options_' . $node->type, array()); $node->comment = variable_get('comment_' . $node->type, 2); unset($node->nid); $node = node_submit($node); $node->uid = $user->uid ? $user->uid : 1; module_invoke('node', 'save', $node); } }
On 6/6/06, Robrecht Jacques <robrechtj+drupal@gmail.com> wrote:
- and the real question: how does the following sequence of 4.6translate into 4.7:
$node->type = 'story'; $node->uid = 1; $node->title = ''; // invalid empty title! $node->body = ''; // invalid empty body!
$node = node_validate($node); // if life was only that
// that easy in 4.7...
if (form_get_errors()) { // we detected the error... do something unset($GLOBALS['form']);
// note: we unset $GLOBALS['form'] so the next time we
// try this trick, form_get_errors() return the errors // of the last run and not of the previous. // If something like this would be possible in 4.7 it // would be great, but form_set_error() in
4.7 saves the
// errors in a static variable inside form_set_error() // instead of in $GLOBALS['form']. I see no way to unset // that... $output .= node_view($node); } else { // no errors? hmm, great, save it... quickly before
// "they" introduce something else that breaks // "common sense". Really: why call something // foobar_validate() if it doesn't validate anything // at all... Am I alone in this? I guess so.
node_save($node); }
Got it. In my case I'm sure those fields are there. But that also tells you the interim (pre-FAPI 2) solution. On 6/7/06, Robrecht Jacques <robrechtj+drupal@gmail.com> wrote:
Despite what the name implies, node_validate() does not validate the node at all. Or at least not completely.
Try to submit a story node using the UI form. If you don't enter a title, you'll get an error (Title is required).
But programmatically :
$node->type = 'story'; $node->uid = 1; $node->title = ''; // invalid empty title! $node->body = ''; // invalid empty body!
// node_validate() does not check the emptiness of title or body // like the UI does, so this validation will work... but shouldn't. node_validate($node);
if (form_get_errors()) { // I would expect to arrive here as the node was not valid (no // non-empty title or body set). } else { // But instead, I arrive here and the node is saved without // trouble. If I go to the edit page of the new node, I'll get // the form_errors again. node_save($node); }
This may be called a bug. Or at least rename node_validate() to node_doesn't_validate().
Robrecht
On 6/7/06, Earl Dunovant <prometheus6@gmail.com> wrote:
Question: since node_validate() really does validate your new node (being a standard story node), why can't you use it?
On 6/7/06, Robrecht Jacques < robrechtj+drupal@gmail.com> wrote:
On 6/7/06, Earl Dunovant <prometheus6@gmail.com> wrote:
With no claim that it's the Right Way(c)
Again, no validation at all.
I know how to create a node programmatically. But this way, you can't be sure it is valid.
Thanks anyway, Robrecht
function syndicator_item_to_node($item_id = NULL) {
global $user; if (is_null($item_id)) { $iid = arg(2); if (isset($iid)) { $item = db_fetch_object(db_query(SYNDICATOR_PROMOTE_TO_NODE_QUERY, $iid)); } } else if (is_numeric($item_id)) { $item = db_fetch_object(db_query(SYNDICATOR_PROMOTE_TO_NODE_QUERY, $item_id)); } if (isset($item)) { $node = new stdClass(); $node->is_new = true; $item->description = check_markup($item->description, $node->filter); $node->created = time(); $node->date = format_date($item->timestamp, 'custom', 'Y-m-d H:i:s O'); $node->type = variable_get('syndicator_publish_node_type', 'none'); $node->title = $item->title; $node->filter = variable_get('filter_default_format', FILTER_FORMAT_DEFAULT); $node->body = theme('syndicator_published_content', $item); $node->teaser = node_teaser(theme('syndicator_published_content', $item), variable_get('filter_default_format', FILTER_FORMAT_DEFAULT)); // might be unnecessary
$node_options = variable_get('node_options_' . $node->type, array()); $node->comment = variable_get('comment_' . $node->type, 2); unset($node->nid); $node = node_submit($node); $node->uid = $user->uid ? $user->uid : 1; module_invoke('node', 'save', $node); } }
On 6/6/06, Robrecht Jacques <robrechtj+drupal@gmail.com> wrote:
- and the real question: how does the following sequence of 4.6translate into 4.7:
$node->type = 'story'; $node->uid = 1; $node->title = ''; // invalid empty title! $node->body = ''; // invalid empty body!
$node = node_validate($node); // if life was only that
// that easy in 4.7...
if (form_get_errors()) { // we detected the error... do something unset($GLOBALS['form']);
// note: we unset $GLOBALS['form'] so the next time we
// try this trick, form_get_errors() return the errors // of the last run and not of the previous. // If something like this would be possible in 4.7 it // would be great, but form_set_error() in
4.7 saves the
// errors in a static variable inside form_set_error() // instead of in $GLOBALS['form']. I see no way to unset // that... $output .= node_view($node); } else { // no errors? hmm, great, save it... quickly before
// "they" introduce something else that breaks // "common sense". Really: why call something // foobar_validate() if it doesn't validate anything // at all... Am I alone in this? I guess so.
node_save($node); }
participants (6)
-
Adrian Rossouw -
Earl Dunovant -
Jeremy Epstein -
Jim Riggs -
Moshe Weitzman -
Robrecht Jacques