function workflow_get_field_name in Workflow 7.2
Same name and namespace in other branches
- 8 workflow.module \workflow_get_field_name()
Determines the Workflow field_name of an entity. If an entity has more workflows, only returns the first one.
Usage if (is_null($field_name = workflow_get_field_name($entity, $entity_type))) { return; // No workflow on this entity } else { ... // WorkflowField or WorkflowNode on this entity }
Parameters
$entity: The entity at hand.
$entity_type:
string $field_name (optional): The field name. If given, will be passed as return value.
$entity_id (optional):
Return value
string
4 calls to workflow_get_field_name()
- workflow_block_view in ./
workflow.block.inc - Implements hook_block_view().
- workflow_node_current_state in ./
workflow.module - Gets the current state ID of a given entity.
- workflow_node_previous_state in ./
workflow.module - Gets the previous state ID of a given entity.
- workflow_tab_access in ./
workflow.module - Menu access control callback. Determine access to Workflow tab.
File
- ./
workflow.module, line 1022 - Support workflows made up of arbitrary states.
Code
function workflow_get_field_name($entity, $entity_type, $field_name = NULL, $entity_id = NULL) {
if (!$entity) {
// $entity may be empty on Entity Add page.
return NULL;
}
if (!is_null($field_name)) {
// $field_name is already known.
return $field_name;
}
// If $field_name is not known, yet, determine it.
if (!$entity_id) {
list($entity_id, , ) = entity_extract_ids($entity_type, $entity);
}
$field_names =& drupal_static(__FUNCTION__);
if (isset($field_names[$entity_type][$entity_id])) {
$field_name = $field_names[$entity_type][$entity_id]['field_name'];
}
else {
$fields = _workflow_info_fields($entity, $entity_type);
if (count($fields)) {
// Get the first field.
// Workflow Field API: return a field name.
// Workflow Node API: return ''.
$field = reset($fields);
$field_name = $field['field_name'];
$field_names[$entity_type][$entity_id]['field_name'] = $field_name;
}
else {
// No workflow at all on this entity.
$field_name = NULL;
// Use special sub-array, or it won't work for NULL.
$field_names[$entity_type][$entity_id]['field_name'] = $field_name;
}
}
return $field_name;
}