Gang,
I'm still only ankle-deep in the Drupal API -- and this probably shows it. BUT, I'm trying to reject a pending content save if the unchanged_node is published. I thought that 'return FALSE' would save me, but it doesn't.
Action: Content is going to be saved. (see config below)
Is there any other way to reject the save so that it doesn't happen? With this, the rejection message is shown, but the content is indeed saved. I did RTFM, but didn't find an answer...
Most gratefully,
TC
array (
'cfg_1' =>
array (
'#module' => 'workflow-ng',
'#event' => 'node_submit',
'#id' => 1,
'#weight' => '-10',
'#type' => 'configuration',
'#label' => 'DisallowEditOfPub-AllowEditUnpub-SetAuthor',
'#active' => 1,
'#altered' => false,
0 =>
array (
'#label' => 'Execute custom PHP code',
'#id' => 2,
'#type' => 'action',
'#name' => 'workflow_ng_action_custom_php',
'#settings' =>
array (
'php' => 'if ([node_unchanged:status] == \'yes\') {
drupal_set_message (\'You may not edit a published item. Change workflow first.\');
return FALSE;
}
else {
$node->status = \'no\';
$node->name = $user->user;
$node->uid = $user->uid;
node_save($node);
return TRUE;
}',
'used_arguments' =>
array (
0 => 'node_unchanged',
),
'used_php_arguments' =>
array (
0 => 'node',
1 => 'user',
),
),
),
1 =>
array (
'#label' => 'Page redirect',
'#id' => 3,
'#type' => 'action',
'#name' => 'workflow_ng_action_drupal_goto',
'#weight' => '5',
'#settings' =>
array (
'path' => 'node/[node:nid]/workflow',
'path_args' =>
array (
0 => 'node',
),
'query' => '',
'query_args' =>
array (
),
'fragment' => '',
'fragment_args' =>
array (
),
'force' => 0,
'override' => 1,
),
),
'#name' => 'cfg_1',
),
)
Comments
Comment #1
ifbyphone1 commentedWell, it looks like the "Content is about to be saved" is post-validation but pre-submit... Now, how to bypass the submit. This has not been easy to google..
Comment #2
amitaibuMaybe replace the node_changed values with the node_unchanged. Like this node will still be saved but with the original values. Sounds a ugly hack, but might work?
Comment #3
ifbyphone1 commentedThanks for the suggestion, Amitaibu -- I thought about that, but the problem is that I'm using this for many different content types, with many different fields. I just found an equally-ugly hack that appears to be working (it is 3:30am here, so no guarantees...).
I used drupal_goto and just force the user to /admin/content/node with a message.
This works for any form, since it just blows past the submit. If I find issues with this, I'll report back.
Comment #4
fagohm, this isn't possible as the node is already being saved - you can't abort at this stage.
Usually one prevents the node save by validation errors on the form, but a working hack might be to just save the "unchanged node". For this you need to use "content has been updated" and just save this node, e.g. by using an action that alters the node or by using a custom php action. Then first the new node will be saved and afterwards you'll overwrite the changes with the old one. Ugly, but it should work (instead of copying fields..).
Comment #5
amitaibutc60045,
Maybe you can write such an action? I can think of several cases when it is needed.
Comment #6
ifbyphone1 commentedfago, you would be surprised to know that a drupal_goto will abort the save. Such a hack on my part, but it works. I was prepared to do as you describe above otherwise!
Comment #7
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.