Skip to content
Permalink
Browse files

README update and module files

  • Loading branch information...
johnrobertwilson committed May 25, 2012
1 parent a13ee2f commit 80b46df9a294784e358b874469d5909fde2a038c
3 README
@@ -0,0 +1,3 @@
This is an example module that extends State Flow.

More information can be found at http://drupal.org/project/state_machine
@@ -0,0 +1,8 @@
name = Phase2 Test Workflow
description = Defines the workflow for content.
core = 7.x
version = 7.x-1.x

dependencies[] = state_flow

files[] = plugins/phase2_workflow.inc
No changes.
@@ -0,0 +1,69 @@
<?php

/**
* Implements hook_permission().
*/
function phase2_workflow_permission() {
return array(
'transition content to the approved state' => array(
'title' => t('Transition content to the approved state.'),
'description' => t('Allows user to transition nodes to the approved state defined in workflow.'),
),
'transition content to the published or unpublished state' => array(
'title' => t('Transition content to the published or unpublished state.'),
'description' => t('Allows user to transition content to the published or unpublished state'),
),
);
}

function phase2_workflow_guard_approve($event, $permission) {
phase2_workflow_guard_permission($event, 'transition content to the approved state');
}

function phase2_workflow_guard_publish($event, $permission) {
phase2_workflow_guard_permission($event, 'transition content to the published or unpublished state');
}

/**
* Helper function for evaluating an access decision with the global permission.
*/
function phase2_workflow_guard_permission($event, $permission) {
// If the user has the global permission, then return TRUE
if (user_access($permission)) {
return TRUE;
}
// Otherwise, return FALSE
return FALSE;
}


/**
* Implements hook_state_flow_plugins().
*/
function phase2_workflow_state_flow_plugins() {
$info = array();
$path = drupal_get_path('module', 'phase2_workflow') . '/plugins';
$info['phase2_workflow'] = array(
'handler' => array(
'parent' => 'state_flow',
'class' => 'Phase2Workflow',
'file' => 'phase2_workflow.inc',
'path' => $path,
),
);
return $info;
}

/**
* Alters the menu access callback for the node Workflow page.
*/
function phase2_workflow_state_flow_menu_node_access_alter(&$access, $node, $account) {
$access = node_access('update', $node, $account);
}

/**
* phase2_workflow_state_flow_machine_type_alter
*/
function phase2_workflow_state_flow_machine_type_alter(&$machine_type, $node) {
$machine_type = "phase2_workflow";
}
@@ -0,0 +1,48 @@
<?php
class Phase2Workflow extends StateFlow {
public function init() {
$this->create_state('draft');
$this->create_state('needs_review');
$this->create_state('approved', array(
'on_enter' => array($this, 'on_enter_approved'),
));
$this->create_state('published');
$this->create_state('unpublished');
$this->create_event('submit_for_review', array(
'label' => t('Submit for review'),
'origin' => 'draft',
'target' => 'needs_review',
));
$this->create_event('approve', array(
'label' => t('Approve'),
'origin' => 'needs_review',
'target' => 'approved',
'guard' => 'phase2_workflow_guard_approve',
));
$this->create_event('request_updates', array(
'label' => t('Request Updates'),
'origin' => array('published', 'approved', 'needs_review'),
'target' => 'draft',
));
$this->create_event('publish', array(
'label' => t('Publish'),
'origin' => 'approved',
'target' => 'published',
'guard' => 'phase2_workflow_guard_publish',
));
$this->create_event('unpublish', array(
'label' => t('Unpublish'),
'origin' => 'published',
'target' => 'unpublished',
'guard' => 'phase2_workflow_guard_publish',
));
}
public function on_enter_approved() {
$node = $this->get_object();
// Do some custom code to fulfill your requirement.
// Perhaps alert the author or some stakeholders
}
}

0 comments on commit 80b46df

Please sign in to comment.
You can’t perform that action at this time.