function workflow_node_current_state in Workflow 7.2
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 workflow.module \workflow_node_current_state()
Gets the current state ID of a given entity.
There is no need to use a page cache. The performance is OK, and the cache gives problems when using Rules.
Parameters
object $entity: The entity to check. May be an EntityDrupalWrapper.
string $entity_type: The entity_type of the entity to check. May be empty in case of an EntityDrupalWrapper.
string $field_name: The name of the field of the entity to check. If NULL, the field_name is determined on the spot. This must be avoided, making multiple workflows per entity unpredictable. The found field_name will be returned in the param. If '', we have a workflow_node mode.
Return value
mixed $sid The ID of the current state.
22 calls to workflow_node_current_state()
- hook_form_workflow_transition_form_alter in ./
workflow.api.php - Implements hook_form_BASE_FORM_ID_alter().
- Workflow::getNextSid in includes/
Entity/ Workflow.php - Returns the next state for the current state.
- workflowfield_field_formatter_view in workflow_field/
workflowfield.formatter.inc - Implements hook_field_formatter_view().
- workflowfield_options_list in workflow_field/
workflowfield.field.inc - Implements hook_options_list().
- workflownode_node_view in workflow_node/
workflownode.module - Implements hook_node_view().
File
- ./
workflow.module, line 690 - Support workflows made up of arbitrary states.
Code
function workflow_node_current_state($entity, $entity_type = 'node', &$field_name = NULL) {
$sid = FALSE;
if (!$entity) {
return $sid;
// <-- exit !!!
}
// If $field_name is not known, yet, determine it.
$field_name = workflow_get_field_name($entity, $entity_type, $field_name);
if (is_null($field_name)) {
// This entity has no workflow.
return $sid;
// <-- exit !!!
}
if ($field_name === '') {
// Workflow Node API: Get current/previous state for a Workflow Node.
// Multi-language not supported.
// N.B. Do not use a page cache. This gives problems with Rules.
$sid = isset($entity->workflow) ? $entity->workflow : FALSE;
}
elseif ($field_name) {
// Get State ID for existing nodes (A new node has no sid - will be fetched later.)
// and normal node, on Node view page / Workflow history tab.
$wrapper = entity_metadata_wrapper($entity_type, $entity);
$sid = $wrapper->{$field_name}
->value();
}
else {
// Not possible. All options are covered.
}
// Entity is new or in preview or there is no current state. Use previous state.
if (!$sid || !empty($entity->is_new) || !empty($entity->in_preview)) {
$sid = workflow_node_previous_state($entity, $entity_type, $field_name);
}
return $sid;
}