As described in Section 5.1, “Overview”, a workflow is a group of
states used to guide content (or any
P4Cms_Record
object) to being published, and each state may express
transitions to other states, which can be restricted by
conditions or enhanced with actions. Development
for workflows focuses on the creation of conditions and actions that can be used by
transitions.
Place condition classes in the module folder, within the
workflows/conditions
folder. Place action classes in the module folder,
within the workflows/actions
folder.
Here is the skeleton of a workflow condition:
<?php /** * A skeleton workflow condition that always evaluates to true. * * @copyright copyright info * @license license info * @version version info */ class Foo_Workflow_Condition_True extends Workflow_ConditionAbstract { /** * Always return true. * * @param Workflow_Model_Transition $transition transition to evaluate this condition for. * @param P4Cms_Record $record record to evaluate this condition for. * @param array|null $pending optional - updated values to consider. * @return bool true no matter what. */ protected function _evaluate( Workflow_Model_Transition $transition, P4Cms_Record $record, array $pending = null) { return true; } }
The $pending
parameter is an array of current
values that may populate a record, and can be compared to the $record
object to determine the differences made during editing.
Here is the skeleton of a workflow action:
<?php /** * A sample workflow action that does nothing. * * @copyright copyright info * @license license info * @version version info */ class Foo_Workflow_Action_Skeleton extends Workflow_ActionAbstract { /** * Does nothing. * * @param Workflow_Model_Transition $transition transition to invoke this action for. * @param P4Cms_Record $record record to invoke this action for. * @return Workflow_ActionInterface provides fluent interface. */ public function invoke(Workflow_Model_Transition $transition, P4Cms_Record $record) { return $this; } }
For details on how to update your workflow configuration to utilize new conditions or actions, please refer to Section 5.6, “Specifying Workflows”.