function _workflow_test_tokens in Workflow 7.2
Test all tokens
File
- ./
workflow.test.inc, line 263 - Contains test functions.
Code
function _workflow_test_tokens($entity_id = 76, $entity_type = 'node', $field_name = NULL) {
global $user;
// $entity_id = 76;
if ($entity_id) {
$node = entity_load_single($entity_type, $entity_id);
}
else {
// Create a node.
$node = new stdClass();
$node->title = "A new Node " . REQUEST_TIME;
$node->type = "WorkfowField";
node_object_prepare($node);
// Sets some defaults. Invokes hook_prepare() and hook_node_prepare().
$node->language = LANGUAGE_NONE;
// Or for example 'en' if locale is enabled.
$node->uid = $user->uid;
$node->status = 1;
//(1 or 0): published or not
$node->promote = 0;
//(1 or 0): promoted to front page
$node->comment = 1;
// 0 = comments disabled, 1 = read only, 2 = read/write
// // Term reference (taxonomy) field
$node->field_workflow[$node->language][]['value'] = 1;
// // Entity reference field
// $node->field_customer_nid[$node->language][] = array(
// 'target_id' => $form_state['values']['entity id'],
// 'target_type' => 'node',
// );
// 'node' is default,
// Other possible values are "user" and "taxonomy_term".
$node = node_submit($node);
// Prepare node for saving
node_save($node);
}
$t_greetings = "\n Hello [current-user:name]!\n <br/>node type + id + title = [node:content-type] + [node:nid] + [node:title]\n ";
$t_node_all = '
<br /> Workflow last transition = [node:last-transition] Last workflow state transition of content.
<br /> Comment comment = [node:last-transition:comment] Workflow executed transition "comment" property.
<br /> Created Medium format = [node:last-transition:created:medium] A date in "medium" format. (Fri, 05/30/2014 - 10:59)
<br /> Created Raw timestamp = [node:last-transition:created:raw] A date in UNIX timestamp format (1401440380)
<br /> Created Seconds-since = [node:last-transition:created:seconds] A date in "seconds ago" format (604800). Use it for easy scheduling workflow transitions.
<br /> Delta = [node:last-transition:delta] Workflow executed transition "delta" property.
<br /> Entity_type = [node:last-transition:entity-type] Workflow executed transition "entity_type" property.
<br /> Field_name = [node:last-transition:field-name] Workflow executed transition "field_name" property.
<br /> label = [node:last-transition:label] Workflow executed transition "label" property.
<br /> Language = [node:last-transition:language] Workflow executed transition "language" property.
<br /> New state = [node:last-transition:new-state] The new state.
<br /> Original workflow state = [node:last-transition:new-state:original] The original workflow state data if the workflow state is being updated or saved.
<br /> State ID = [node:last-transition:new-state:sid] The State ID.
<br /> State label = [node:last-transition:new-state:label] The state label.
<br /> Status = [node:last-transition:new-state:status] Workflow state "status" property.
<br /> Sysid = [node:last-transition:new-state:sysid] Workflow state "sysid" property.
<br /> URL = [node:last-transition:new-state:url] The URL of the workflow state.
<br /> Weight = [node:last-transition:new-state:weight] Workflow state "weight" property.
<br /> Wid = [node:last-transition:new-state:wid] Workflow state "wid" property.
<br /> Nid = [node:last-transition:nid] Workflow executed transition "nid" property.
<br /> Old_sid = [node:last-transition:old-sid] Workflow executed transition "old_sid" property.
<br /> Revision_id = [node:last-transition:revision-id] Workflow executed transition "revision_id" property.
<br /> Sid = [node:last-transition:sid] Workflow executed transition "sid" property.
<br /> Stamp = [node:last-transition:stamp] Workflow executed transition "stamp" property.
<br /> Uid = [node:last-transition:uid] Workflow executed transition "uid" property.
<br /> Old state = [node:last-transition:old-state] The old state.
<br /> Original workflow state = [node:last-transition:old-state:original] The original workflow state data if the workflow state is being updated or saved.
<br /> State ID = [node:last-transition:old-state:sid] The State ID.
<br /> State label = [node:last-transition:old-state:label] The state label.
<br /> Status = [node:last-transition:old-state:status] Workflow state "status" property.
<br /> Sysid = [node:last-transition:old-state:sysid] Workflow state "sysid" property.
<br /> URL = [node:last-transition:old-state:url] The URL of the workflow state.
<br /> Weight = [node:last-transition:old-state:weight] Workflow state "weight" property.
<br /> Wid = [node:last-transition:old-state:wid] Workflow state "wid" property.
<br /> User = [node:last-transition:user] The user that executed the transition.
<br /> Created = [node:last-transition:user:created] The date the user account was created.
<br /> Default theme = [node:last-transition:user:theme] The user"s default theme.
<br /> Edit URL = [node:last-transition:user:edit-url] The URL of the account edit page.
<br /> Email = [node:last-transition:user:mail] The email address of the user account.
<br /> Last access = [node:last-transition:user:last-access] The date the user last accessed the site.
<br /> Last login = [node:last-transition:user:last-login] The date the user last logged in to the site.
<br /> Name = [node:last-transition:user:name] The login name of the user account.
<br /> Original user = [node:last-transition:user:original] The original user data if the user is being updated or saved.
<br /> Picture = [node:last-transition:user:picture] The picture of the user.
<br /> Roles = [node:last-transition:user:roles] The user roles associated with the user account.
<br /> Status = [node:last-transition:user:status] Whether the user is active or blocked.
<br /> URL = [node:last-transition:user:url] The URL of the account profile page.
<br /> User ID = [node:last-transition:user:uid] The unique ID of the user account.
<br /> Workflow = [node:last-transition:Workflow] Workflow the state belongs to.
<br /> Workflow ID = [node:last-transition:Workflow:wid] The ID used to identify this workflow internally.
<br /> Module = [node:last-transition:Workflow:module] Workflow "module" property.
<br /> Options = [node:last-transition:Workflow:options] Workflow "options" property.
<br /> Original workflow = [node:last-transition:Workflow:original] The original workflow data if the workflow is being updated or saved.
<br /> States of this Workflow = [node:last-transition:Workflow:states] States of this Workflow
<br /> Status = [node:last-transition:Workflow:status] Workflow "status" property.
<br /> Tab_roles = [node:last-transition:Workflow:tab-roles] Workflow "tab_roles" property.
<br /> Transitions of this Workflow = [node:last-transition:Workflow:transitions] Transitions of this Workflow
<br /> URL = [node:last-transition:Workflow:url] The URL of the workflow.
<br /> Workflow ID = [node:last-transition:Workflow:wid] The unique ID of the workflow applied to this node.
<br /> Workflow label = [node:last-transition:Workflow:label] The workflow applied to this node.
<br /> Workflow executed transition ID = [node:last-transition:hid] The unique ID of the workflow executed transition.
';
// This text is to test only a few tokens, for better inspection.
$t_node_sub = '
<br /> User = [node:last-transition:user] The user that executed the transition.
<br /> label = [node:last-transition:label] Workflow executed transition "label" property.
';
// todo : test old-state
$data = array();
$data['node'] = $node;
$data['entity'] = $node;
$data['entity_type'] = 'node';
// Display the tokenized text.
dpm($node);
dpm(token_replace($t_greetings, $data));
dpm(token_replace($t_node_all, $data));
// dpm(token_replace( $t_node_sub, $data));
}