0

I have another "interesting" problem using Workbench Moderation. I'm using Workbench for workflow, along with Workbench Access, Workbench Moderation (7.x-1.3) and Workbench Moderation Notes on a new Drupal 7 site.

I have created a custom Approvers field on my content type that editors will use to select which approver should receive the notification email. This is a list field where the approver name is displayed for selection (the label) and the associated value (key) is the email address of the approver. The latter is to be used in a rule to send the email to the correct address. I have written some PHP to extract the value from the selected item in this Approvers list field:

<?php 

$node_id = arg(1);
$node = node_load($node_id);
$fieldname='field_approvers';
 $items = field_get_items('node', $node, $fieldname);
if($items)
{
$key = $items[0]['value'];
echo "key = ". $key;
}
else
{
echo $node_id;
}
?>

Note that this is inserted in a block for testing purposes and I am not very experienced in PHP (or Drupal for that matter!).

While testing, I have discovered that before publishing the node, all works well and I can extract the correct email address. However, similar to my issue yesterday (Workbench Moderation - Issues with New Drafts of Published Nodes), once a node is published and set back to draft, things stop working properly. The published value of the list field is always returned, even when the list field itself shows the correct new approver. So, if I set back to draft and change the approver in the list field, the PHP code will always return the value from the published version of the node. I have debugged the node and checked the database and the web and I can't figure out how to get the Approvers list field value from the current revision.

1

Due to the underwhelming response, I had to figure it out for myself :-). To save any other newbie hours of angst, here is the solution:

As predicted, the answer was simple, but finding it was the problem! I eventually found how to load the latest revision by looking at the workbench moderation module source code. If you add the line under the $node variable assignation below, it will return the value on the current revision:

<?php 

$node_id = arg(1);
$node = node_load($node_id);
$node = workbench_moderation_node_current_load($node); //NEW LINE!
$fieldname='field_approvers';
$items = field_get_items('node', $node, $fieldname);
if($items)
{
 $key = $items[0]['value'];
 echo "key = ". $key;
}
else
{
 echo $node_id;
}
?>

Hope this helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.