function workflow_node_current_state in Workflow 7
Same name and namespace in other branches
- 8 workflow.module \workflow_node_current_state()
- 5.2 workflow.module \workflow_node_current_state()
- 5 workflow.module \workflow_node_current_state()
- 6.2 workflow.module \workflow_node_current_state()
- 6 workflow.module \workflow_node_current_state()
- 7.2 workflow.module \workflow_node_current_state()
Get the current state of a given node.
Parameters
$entity: The entity to check.
Return value
The ID of the current state.
10 calls to workflow_node_current_state()
- WorkflowDefaultWidget::submit in includes/
Field/ WorkflowDefaultWidget.php - workflow_cron in ./
workflow.module - Implements hook_cron().
- workflow_execute_transition in ./
workflow.module - Execute a transition (change state of a node). @deprecated: workflow_execute_transition() --> WorkflowTransition::execute().
- workflow_field_choices in ./
workflow.node.inc - Get the states current user can move to for a given node.
- workflow_node_view in ./
workflow.node.inc - Implements hook_node_view().
File
- ./
workflow.module, line 463 - Support workflows made up of arbitrary states.
Code
function workflow_node_current_state($entity, $entity_type = 'node', $field = array()) {
$sid = FALSE;
$state = FALSE;
// Field API: Get current/previous state.
if ($field) {
$field_name = $field['field_name'];
if (isset($entity->is_new) && $entity->is_new == TRUE) {
// A new node.
$workflow = Workflow::load($field['settings']['wid']);
$sid = $workflow
->getCreationSid();
}
elseif (isset($entity->original)) {
// A changed node.
$referenced_entity = $entity->original;
$items = field_get_items($entity_type, $referenced_entity, $field_name);
$sid = _workflow_get_sid_by_items($items);
}
else {
// A normal node, on Node view page / Workflow history tab.
$items = field_get_items($entity_type, $entity, $field_name);
$sid = _workflow_get_sid_by_items($items);
}
// No current state. Use creation state.
if (empty($sid)) {
$workflow = Workflow::load($field['settings']['wid']);
$sid = $workflow
->getCreationSid();
}
return $sid;
}
// Node API: Get current/previous state.
// There is no nid when creating a node.
$entity_type = 'node';
if (!$sid && !empty($entity->nid)) {
$state = workflow_get_workflow_node_by_nid($entity->nid);
if ($state) {
$sid = $state->sid;
}
}
if (!$sid && !empty($entity->type)) {
// No current state. Use creation state.
if ($workflow = workflow_get_workflows_by_type($entity->type, $entity_type)) {
$sid = $workflow
->getCreationSid();
}
}
return $sid;
}