Class SimpleWorkflowBehavior
SimpleWorkflowBehavior implements the behavior of a model evolving inside a Simple Workflow.
To use SimpleWorkflowBehavior with the default parameters, simply attach it to the model class like you would do for any standard Yii2 behavior.
use raoul2000\workflow\base\SimpleWorkflowBehavior; public function behaviors() { return [ 'simpleWorkflow' => [ 'class' => SimpleWorkflowBehavior::className() ], ]; }
To learn more about Yii2 behaviors refer to the Yii2 Definitive Guide
You can customize the SimpleWorkflowBehavior with the following parameters :
statusAttribute
: name of the attribute that is used by the owner model to hold the status value. The default value is "status".defaultWorkflowId
: identifier of the default workflow for the owner model. If no value is provided, the behavior creates a default workflow identifier (see [[getDefaultWorkflowId]]).source
: name of the Workflow Source Component that the behavior uses to read the workflow definition. By default the component id "workflowSource" is used. If it is not already available in the current application it is created by the behavior using the default workflow source component class.
Below is an example behavior initialization :
use raoul2000\workflow\base\SimpleWorkflowBehavior; public function behaviors() { return [ 'simpleWorkflow' => [ 'class' => SimpleWorkflowBehavior::className(), 'statusAttribute' => 'col_status', 'defaultWorkflowId' => 'MyWorkflow', 'source' => 'myWorkflowSource', ], ]; }
- yii\base\Behavior
- raoul2000\workflow\base\SimpleWorkflowBehavior
Methods summary
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
boolean
|
#
enterWorkflow( string $workflowId = null )
Puts the owner model into the workflow |
public
|
#
afterSaveStatus( yii\base\Event $event )
After the owner model has been saved, fire pending events. This is the event handler for both ActiveRecord::EVENT_AFTER_UPDATE and ActiveRecord::EVENT_AFTER_INSERT events |
public
|
#
beforeSaveStatus( yii\base\Event $event )
Send owner model into status if needed. This is the event handler for both ActiveRecord::EVENT_BEFORE_INSERT and ActiveRecord::EVENT_BEFORE_UPDATE events |
public
|
#
beforeDelete( yii\base\Event $event )
Handle the case where the owner model is leaving the workflow. This is the event handler for ActiveRecord::EVENT_BEFORE_DELETE |
public
|
#
afterDelete( yii\base\Event $event )
Fires pending events, once the owner model has been successfully deleted. This is the event handler for ActiveRecord::EVENT_AFTER_DELETE |
public
boolean
|
#
sendToStatus(
Send the owner model into the status passed as argument. |
public
|
#
getEventSequence( string $status )
Creates and returns the list of events that will be fire when the owner model is sent from its current status to the one passed as argument. |
public
string[]
|
#
getScenarioSequence( string $status )
Creates and returns the list of scenario names that will be used to validate the owner model when it is sent from its current status to the one passed as argument. |
public
array
|
#
createTransitionItems( mixed $status, boolean $WithScenarioNames, boolean $withEventSequence )
Creates and returns workflow event sequence and/or scenario for the pending transition. |
public
array
|
#
getNextStatuses( $validate = false, $beforeEvents = false )
Returns all status that can be reached from the current status. |
public
string
|
|
public
|
#
getWorkflowSource( )
Returns the Workflow Source Component used by this behavior. This component is initialized by the [[$source]] configuration property. If not configured, the behavior creates and register its own workflow source component. |
public
null|
|
#
getStatusAccessor( )
Returns the status accessor instance used by this behavior or NULL if no status accessor is used. This component is initialized by the [[$statusAccessor]] configuration property. |
public
null|
|
#
getStatusConverter( )
Returns the status converter instance used by this behavior or NULL if no status converter is used. This component is initialized by the [[$statusConverter]] configuration property. |
public
null|
|
|
public
null|
|
#
getWorkflow( )
Returns the current Workflow instance the model is in or NULL if the model is not in a workflow. |
public
boolean
|
#
hasWorkflowStatus( )
Returns a value indicating whether the owner model is currently in a workflow or not. |
public
boolean
|
#
statusEquals(
Tests if the current status is equal to the status passed as argument. |
public static
boolean
|
#
isAttachedTo( yii\db\BaseActiveRecord $model )
Tests that a |
Constants summary
string |
DEFAULT_SOURCE_CLASS
Name of the class used to instantiate the default workflow source component if not configured. |
#
'raoul2000\workflow\source\file\WorkflowFileSource'
|
string |
DEFAULT_EVENT_SEQUENCE_CLASS
Name of the class used to instantiate the default event sequence if not configured. |
#
'raoul2000\workflow\events\BasicEventSequence'
|
string |
EVENT_BEFORE_CHANGE_STATUS
Name of the default workflow event fired before the owner model change status. |
#
'EVENT_BEFORE_CHANGE_STATUS'
|
string |
EVENT_AFTER_CHANGE_STATUS
Name of the default workflow event fired after the owner model change status. |
#
'EVENT_AFTER_CHANGE_STATUS'
|
Properties summary
public
string
|
$statusAttribute
name of the owner model attribute used to store the current status value. It is also possible to use a model property but in this case you must provide a suitable status accessor component that will handle status persistence. |
#
'status'
|
public
string
|
$source
name of the workflow source component to use with the behavior |
#
'workflowSource'
|
public
null|string|array|object
|
$statusConverter
The status converter component definition or NULL (default) if no
status converter is used by this behavior.
Note that the status converter configured here must implement the
|
#
null
|
public
null|string|array|object
|
$statusAccessor
The status accessor component definition or NULL (default) if no
status accessor is used by this behavior.
Note that the status accessor configured here must implement the
|
#
null
|
public
string
|
$eventSequence
name of the event sequence provider component. If the component does not exist it is created by this behavior using the default event sequence class. Set this attribute to NULL if you are not going to use any Workflow Event. |
#
'eventSequence'
|
public
boolean|string
|
$autoInsert
(not enabled) if TRUE, the model is automatically inserted into the default workflow. If
|
#
false
|
public
boolean
|
$propagateErrorsToModel
If TRUE, all errors that may be registred on an invalidated 'before' event, are assigned to the status attribute of the owner model. |
#
false
|
public
boolean
|
$stopOnFirstInvalidEvent
if TRUE, all "before" events are fired even if one of them is invalidated by an attached handler. When FALSE, the first invalidated event interrupts the event sequence. Note that if an event is attached to several handlers, they will all be invoked unless the event is invalidated and marked as handled. |
#
true
|
public
boolean
|
$fireDefaultEvent
When TRUE, a default event is fired on each status change, including when the model enters or leaves the workflow and even if no event sequence is configured. When FALSE the default event is not fired. |
#
true
|