raoul2000\workflow\events\WorkflowEvent::beforeLeaveStatus PHP Method

beforeLeaveStatus() public static method

Create name for a *before leave status* event.
public static beforeLeaveStatus ( string $status = self::ANY_STATUS ) : string
$status string the status name or any status if not set
return string name of the event
    public static function beforeLeaveStatus($status = self::ANY_STATUS)
    {
        self::_checkNonEmptyString('status', $status);
        return 'beforeLeaveStatus{' . $status . '}';
    }

Usage Example

 public function testStopOnFirstInvalidEventFalse()
 {
     // prepare item instance
     $item = new Item00();
     $item->attachBehavior('workflowBehavior', ['class' => SimpleWorkflowBehavior::className(), 'defaultWorkflowId' => 'Item04Workflow', 'propagateErrorsToModel' => true, 'stopOnFirstInvalidEvent' => false]);
     $item->on(WorkflowEvent::beforeLeaveStatus('Item04Workflow/A'), [$this, 'invalidateEvent1']);
     $item->on(WorkflowEvent::beforeEnterStatus('Item04Workflow/B'), [$this, 'invalidateEvent2']);
     verify('stopOnFirstInvalidEvent is true', $item->stopOnFirstInvalidEvent)->false();
     $item->sendToStatus('Item04Workflow/A');
     verify('item is in status A', $item->getWorkflowStatus()->getId())->equals('Item04Workflow/A');
     verify('item has no error', $item->hasErrors())->false();
     // send to B
     $item->sendToStatus('B');
     expect('status is still A', $item->getWorkflowStatus()->getId())->equals('Item04Workflow/A');
     expect('item has error', $item->hasErrors())->true();
     expect('1 error message is set for attribute "status"', count($item->getErrors('status')))->equals(2);
     $errorMessages = $item->getErrors('status');
     expect('First error message is "err_message_1" ', $errorMessages[0])->equals("err_message_1");
     expect('Second error message is "err_message_2" ', $errorMessages[1])->equals("err_message_2");
 }
All Usage Examples Of raoul2000\workflow\events\WorkflowEvent::beforeLeaveStatus