-
Notifications
You must be signed in to change notification settings - Fork 71
Workflow faq
By default the workflow engine looks up any "Parent" relationship to find inherited workflow definitions. Obviously for top level pages this doesn't go anywhere (as ParentID = 0). However, the workflow engine allows a user to define a workflowParent method in a class, which can be used to look at another object for inheriting from. A typical usecase would be for a Page class to look at a SiteConfig for workflow settings, eg
mysite/_config.php
Object::add_extension('SiteConfig', 'WorkflowApplicable');
Object::add_extension('SiteTree', 'WorkflowApplicable');
mysite/code/Page.php
class Page extends SiteTree {
// other code
public function workflowParent() {
return SiteConfig::current_site_config();
}
// other code
}
class Page_Controller extends ContentController {
}
The above code will mean that if a workflow is not defined for one particular page, it will next look at the SiteConfig to find the applicable workflow to apply. If you want to extend that a little further and follow the page inheritance, then use the below method instead. This will mean that it will only fall back on the SiteConfig workflow definition if no page in the parent hierarchy has a specific workflow set.
class Page extends SiteTree {
/**
* This allows workflow to be inherited by parent, and if the parent doesn't exist, fall over to the SiteConfig
* workflow setting. This means that if a page with children changes the workflow, it will change the workflow for
* all those children as well, not just itself. If there is no workflow defined on this page, and this page has no
* direct parent (e.g. it's a root-level page in the CMS tree), then return the SiteConfig and let the default
* setting in SiteConfig configure what workflow definition to use.
*
* @return DataObject The DataObject where the workflow inheritance should flow to next
*/
function workflowParent() {
if($this->ParentID == 0)
return SiteConfig::current_site_config();
else
return $this->Parent();
}
}
Yes, but only if you're willing to write a bunch of code around how it's applied to files and how a workflow is 'started' for a file. There are plans to integrate this with versioned files in a much better way of doing things, but until then it's best to avoid this extension.
It's a workflow driven alternative to the MultiForm module. More details on how to use it will be provided later...