function _workflow_rules_set_state in Workflow 7.2
Action implementation: set current state, ignoring current user permission.
For both Workflow Node and Workflow Field.
2 string references to '_workflow_rules_set_state'
- _workflowfield_rules_action_info in workflow_rules/
workflow_rules.field.inc - Implements subfunction of hook_rules_action_info().
- _workflownode_rules_action_info in workflow_rules/
workflow_rules.node.inc - Implements subfunction of hook_rules_action_info().
File
- workflow_rules/
workflow_rules.rules-callback.inc, line 128 - Callback implementations for Rules integration for the Workflow module.
Code
function _workflow_rules_set_state(array $parameters, RulesAction $action) {
global $user;
// Warning: keep this action in line between Workflow Field and Workflow Node.
// "$parameters['node']" is for backwards compatibility: can be any entity_type.
$entity = $parameters['node']
->value();
// $parameters['entity'] is an EntityDrupalWrapper.
$entity_type = $parameters['node']
->type();
// This is a poorman's effort to convert a token into a field name.
$field_name = isset($parameters['settings']['field:select']) ? _workflow_rules_token_replace($parameters['settings']['field:select']) : '';
$old_sid = workflow_node_current_state($entity, $entity_type, $field_name);
// Select the last state on the list.
$new_sid = array_pop($parameters['workflow_state']);
if ($new_sid == 'ANY') {
$new_sid = $old_sid;
}
$comment = $parameters['workflow_comment'];
$transition = new WorkflowTransition();
$transition
->setValues($entity_type, $entity, $field_name, $old_sid, $new_sid, $user->uid, REQUEST_TIME, $comment);
// Force this transition, to ignore the limitations on the current user's permissions.
$transition
->force(TRUE);
// Execute the transition. It may bounce, due to extra checks.
// @todo: use $new_sid = $transition->execute() without generating infinite loops.
// Below method does not recalc tokens on automatic_entity_label.
$new_sid = workflow_execute_transition($entity_type, $entity, $field_name, $transition);
}