automatic title with manual node creation

srodriguez - October 23, 2008 - 18:54
Project:Automatic Nodetitles
Version:5.x-1.1
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

I was having this issue of my automatic title being left blank when I would create a node with a content type using auto node titles. I was wanting to pull back a taxonomy term and I made the vocab weights higher to make sure the correct term was selected. Even with this when the node was being submitted the title would be left blank until the node was edited.

I modified the hook_nodeapi and added this bit of code and my titles are now added when the node is created.

if ($op == 'insert') {
auto_nodetitle_set_title($node);
node_save($node);
    }

here is a copy of the complete function

/**
* Implementation of hook_nodeapi().
*/
function auto_nodetitle_nodeapi(&$node, $op, $form = NULL, $a4 = NULL) {
  if ($op == 'validate') {
    if ((auto_nodetitle_get_setting($node->type) == AUTO_NODETITLE_ENABLED) || ((auto_nodetitle_get_setting($node->type) == AUTO_NODETITLE_OPTIONAL) && empty($node->title))) {
      /*
       * Sets the node title.
       * We need to do this on validation because of two points:
       *     It's early engouh to have node previews working and
       *     it's late enough as CCK has already gone through the 'process form values' step
       *
       * As changes to $node are not persistent during validation, we use form_set_value()!
       */
      auto_nodetitle_set_title($node);
      form_set_value($form['title'], $node->title);
    }
  }
if ($op == 'insert') {
auto_nodetitle_set_title($node);
node_save($node);
    }
 

}

I hope this helps someone with a similar problem

#1

srodriguez - October 24, 2008 - 18:22

It should be like this

  if ($op == 'insert') {
    if ((auto_nodetitle_get_setting($node->type) == AUTO_NODETITLE_ENABLED) || ((auto_nodetitle_get_setting($node->type) == AUTO_NODETITLE_OPTIONAL) && empty($node->title))) {
      auto_nodetitle_set_title($node);
      node_save($node);
    }
  }

#2

fago - October 28, 2008 - 14:43
Title:[term] Token not creating automatic title on node creation» automatic title with manual node creation

hm, yes the automatic title is currently only generated when the usual node form is used. Perhaps we should add such a nodeapi implementation too.

#3

kenorb - November 11, 2008 - 11:52

subscribing

#4

Summit - November 24, 2008 - 10:30

Subscribing,
greetings,
Martijn

#5

flevour - November 24, 2008 - 23:10

Hi,
I think this is one of the main issues for this little but effective module. I could easily find similar posts while quickly scanning through the issue queue. If some simple fix (instead of going through the installation of workflow-ng and an extensions, aso you mentioned somewhere in the queue) could get in, I am sure everyone (including the issue queue) could benefit from this.
Thanks,
Francesco

#6

fago - December 30, 2008 - 20:09
Status:active» fixed

I've just improved the module to also work on node api, check http://drupal.org/node/348860.

#7

System Message - January 13, 2009 - 20:10
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.