I used another module for this for a while, but it was buggy and didn't always set the title correctly, which was a pain since I'd have to edit every node of a specific content type twice to fix it. I started looking a bit more at Workflow-ng and realized I could do the same thing, with half the headaches. The newest problem is.. the node title, and pathauto urls get set perfectly and there doesn't appear to be any other problems with the information in the node values.. however, when I create a new node it saves it with the desired title values but drupal core also spits out a ton of errors at the same time. I was thinking perhaps my rule config was off or something.. anyone have any advice?

Here's the rule config at the moment.

array (
  'cfg_1' => 
  array (
    '#active' => 1,
    '#module' => 'workflow-ng',
    '#type' => 'configuration',
    '#label' => 'set stream title',
    '#weight' => '0',
    '#altered' => false,
    '#event' => 'node_submit',
    '#id' => 1,
    0 => 
    array (
      '#type' => 'action',
      '#label' => 'Execute custom PHP code',
      '#name' => 'workflow_ng_action_custom_php',
      '#id' => 4,
      '#settings' => 
      array (
        'php' => '$node->title = "[node:field_gamevid_stream-term] - [node:field_gamevid_stream_num-formatted]";
',
        'used_arguments' => 
        array (
          0 => 'node',
        ),
        'used_php_arguments' => 
        array (
          0 => 'node',
        ),
      ),
    ),
    1 => 
    array (
      '#type' => 'condition',
      '#id' => 3,
      '#name' => 'workflow_ng_condition_content_is_type',
      '#settings' => 
      array (
        'type' => 
        array (
          'gamevid_stream_episode' => 'gamevid_stream_episode',
        ),
      ),
      '#argument map' => 
      array (
        'node' => 'node',
      ),
    ),
    '#name' => 'cfg_1',
  ),
)

and here's the complaint I'm getting from drupal when a new node of this type is created


    * warning: Invalid argument supplied for foreach() in /usr/home/kurogames/public_html/modules/node/node.module on line 521.
    * warning: implode() [function.implode]: Invalid arguments passed in /usr/home/kurogames/public_html/modules/node/node.module on line 525.
    * user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 query: SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM node n INNER JOIN users u ON u.uid = n.uid INNER JOIN node_revisions r ON r.vid = n.vid WHERE in /usr/home/kurogames/public_html/includes/database.mysql.inc on line 172.

Comments

amitaibu’s picture

Maybe this patch can help you #235438: Populate a field action?

Rysk’s picture

hmm... managed to apply the patch manually since the diff is different between the current version and the version that was used when that patch was made. I'm still getting the same error, at the moment using this action when content is created and populating the field with the author's name. I think what's making this the most difficult at the moment though, is that I can't tell what arguments are being passed when the node save function is being called.

fago’s picture

I assume the tokens cause your error. Try it again, with setting the title to 'a afixed value' and don't use any tokens.

Rysk’s picture

I tried that, and I still seem to be getting the same error. When I look through the source of the core node.module at the lines that are giving errors, it looks more like it's not outputting a proper node id for some reason, but this only happens when I use workflow-ng or auto nodetitle to set the node titles, with or without tokens in the title string.

Rysk’s picture

Got it figured out, by changing the variable when the content is created rather than when it's initially saved. Of course from what I understand, this means that it'll probably double the amount of database transactions every time a new content type is created of a particular type but that really shouldn't matter too much.

array (
  'cfg_5' => 
  array (
    '#active' => 1,
    '#label' => 'set game ep title',
    '#type' => 'configuration',
    '#weight' => '0',
    '#id' => 1,
    '#module' => 'workflow-ng',
    '#event' => 'node_insert',
    '#altered' => false,
    0 => 
    array (
      '#type' => 'condition',
      '#name' => 'workflow_ng_condition_content_is_type',
      '#id' => 2,
      '#settings' => 
      array (
        'type' => 
        array (
          'game_series_episode' => 'game_series_episode',
        ),
      ),
      '#argument map' => 
      array (
        'node' => 'node',
      ),
    ),
    1 => 
    array (
      '#type' => 'action',
      '#name' => 'workflow_ng_action_custom_php',
      '#settings' => 
      array (
        'php' => '$node->title = "[node:term-raw] - Episode [node:field_game_episode_number-formatted]";
node_submit($node);
node_save($node);
',
        'used_arguments' => 
        array (
          0 => 'node',
        ),
        'used_php_arguments' => 
        array (
          0 => 'node',
        ),
      ),
      '#id' => 3,
      '#label' => 'Execute custom PHP code',
    ),
    '#name' => 'cfg_5',
  ),
)
Rysk’s picture

Not sure if anyone's using this as a template for their own node auto-title setup, but I found a bug with my setup. If you're using CCK fields in the content type then the custom code needs to be a little different, change this:

'$node->title = "[node:term-raw] - Episode [node:field_game_episode_number-formatted]";
node_submit($node);
node_save($node);

to this:

'$node->title = "[node:term-raw] - Episode [node:field_game_episode_number-formatted]";
node_save($node);

the reason being that the node_submit($node) line strips out some of the CCK fields and it can mess things up a little by saving blank values to your fields.

amitaibu’s picture

Aren't you actually looking for http://drupal.org/project/auto_nodetitle ?

fago’s picture

Status: Active » Fixed

actually it would be better if you just use return array('node' => $node); - so workflow-ng would handle node saving for you. So if you use another action, the node will be saved only once.

Rysk’s picture

In reply to #7:
The problem with using Auto Nodetitle in this case is, with the way node submit works from what I've found through several tests taxonomy terms aren't saved or available to pass as an argument or value until after the node is created. So if you're trying to use term values in the actual content title, it'll either set incomplete or blank or incomplete values, or at worst it'll create the node but it'll spit out a ton of errors as well since it's trying to force it to save with incomplete values that don't make it to the submit function. Using workflow-ng to set it and save after it's been created is the only way I've found to make it actually work so far. Plus as a matter of personal preferance, I don't want to bloat my drupal install with hundreds of little modules to do small things here and there if I can come up with a solution using the modules I have. Right now I'm running a streaming media site that consists of drupal, views, cck, workflow-ng, and a few other smaller modules such as advanced profile/forums. the fewer non-core modules, the better for what I'm trying to do. Try it yourself, maybe you'll find a method I haven't tried yet.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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