When I use one of my CCK fields' tokens in the title, I get the default date for that field, not the one that has been set in the node. Thus the value of the date can be May 5, 1885, but in the title it will come out as January 31, 2007.

Comments

fago’s picture

hm, could you please test again with the latest module?
I've just committed some enhancements.

ray007’s picture

I just tested with the lasted dev snapshot, and my title still ends up "1. January 2007" ...

karens’s picture

I found the problem. Auto_nodetitles is creating a title for the node without calling _content_widget_invoke('process form values', $node) first. That creates a node that has the unprocessed date input values (which are not valid dates themselves) which then fails when it tries to turn those values into formatted dates. 'Process form values' is the step that converts string text and arrays of month/day/year into valid dates, so it is critical.

If you can find a way to run _content_widget_invoke('process form values', $node) on the node values before creating the title it should work right. I dug around in the code but couldn't find the right place to catch this and correct it.

The other question is whether this should be done here or in the token module. I'm not familiar enough with either to be sure where this should take place.

fago’s picture

thanks KarenS.

CCK does this call on hook_nodeapi type submit, so we could fix this by let the auto_nodetitle module come after CCK (adapt module ordering). Imho that's the appropriate fix. I'll have a look at it as soon as time permits.

ray007’s picture

StatusFileSize
new656 bytes

The signature of auto_nodetitle_validate() did confuse me a bit a first, since it's quite different from what api.drupal.org says about hook_validate(), but the following patch (also attached) seems to do good work ...

Index: auto_nodetitle.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/auto_nodetitle/auto_nodetitle.module,v
retrieving revision 1.4.2.10
diff -u -r1.4.2.10 auto_nodetitle.module
--- auto_nodetitle.module	10 Feb 2007 19:33:56 -0000	1.4.2.10
+++ auto_nodetitle.module	12 Feb 2007 09:20:59 -0000
@@ -51,6 +51,7 @@
  */
 function auto_nodetitle_validate($form_id, $form_values, $form) {
   $node = (object)$form_values;
+  _content_widget_invoke('process form values', $node);
   auto_nodetitle_set_title($node);
   form_set_value($form['title'], $node->title);
 }

Btw: is there a reason the parameters $form_values and $form are not declared as references?

fago’s picture

Have you read my last post?
If you'd like to help, please do it that way.

@hook_validate: yes the function name is somehow misleading, it's no implementation of hook_validate. I've renamed it to auto_nodetitle_form_validate().

ray007’s picture

Just increasing the weight of the auto_nodetitle module didn't change anything.
We probably need to implement a hook_nodeapi() and put the title-update there?

fago’s picture

I've done so, are you using the latest module?

ray007’s picture

Yes, downloaded the dev-version this morning, so it doesn't have the renamed function in it, but that shouldn't matter.

I've adjusted the weight in the system table (just set it to 5), but that doesn't change anything.
I didn't check whether the call passed actually the if-check in the hook ... and there there someone after us writing everything to DB?

ray007’s picture

StatusFileSize
new777 bytes

If we use the 'validate' op in hook_nodeapi, it all works.
Not sure why why still need to do the call in auto_nodetitle_form_validate() too, but it didn't work when I removed the call to auto_nodetitle_set_title() there.

Patch to the module is attached, but stupid cvs doesn't let me create a patch for a file not yet existing in the repository, so here a auto_nodetitle.install file adjusting the weight:

<?php
// $Id$

/**
 * Implementation of hook_install().
 */
function auto_nodetitle_install() {
}

/**
 * make sure hooks are invoked after cck main hooks
 */
function auto_nodetitle_update_1() {
  $ret = array();
  $ret[] = update_sql("UPDATE {system} SET weight = 5 WHERE name = 'auto_nodetitle'");
  return $ret;
}
fago’s picture

ok, I had a closer look at this.

Setting the weight to 5 fixed it for 'submit', so the title has been set correctly, however there was still an error caused by the validation. auto_nodetitle did its validation through a formAPI submit handler, which was called before CCK so the form values were not processed => error.

I've changed this now to hook_nodeapi like you did, however then setting $node->title is not enough as the changes to $node on validation will not be persistent. (that's why you still needed the formapi validation)

So i did

function auto_nodetitle_nodeapi(&$node, $op, $form = NULL, $a4 = NULL) {
  if ($op == 'validate' && variable_get('ant_'. $node->type, 0)) {
    auto_nodetitle_set_title($node);
    form_set_value($form['title'], $node->title);
  }
}

Which sets the nodetitle in $form_values and so in the resulting $node.

KarenS, while debugging this stuff I saw that CCK is processing the form values three times. I think this should be done only once: on nodeapi $op validate like now, but with setting the changes through form_set_value(), so that they are persistent. That would save two times executing "prepare form values": on nodeapi $op submit and inside content_view().

fago’s picture

Status: Active » Fixed

ah I forgot, I tested this with the date field and it does work now as good as the token module does support the cck dates..

-> committed in 5.x and HEAD.

fago’s picture

for reference: I've opened a CCK issue for invoking "process form values" only once:
http://drupal.org/node/118645

ray007’s picture

Hope they don't break us when they fix it ;-)

Anonymous’s picture

Status: Fixed » Closed (fixed)