Skip to content

Workflow initial_marking is optional and entered event on initial_marking is not dispatched #37421

@pluk77

Description

@pluk77

The 'initial_marking' option seems to be optional as the first defined place will be used as the initial marking if 'initial_marking' is not defined. It therefore only seems useful when the initial_marking differs from the first marking defined in places.

It is therefore also impossible to have a blank marking after interacting with the workflow, even if the initial_marking is not set as it will be set to the first state automatically.

On top of this, the 'entered' event is not dispatched when the object moves to its initial marking as there is no transition.

We found this out the hard way when using workflow->getMarking($object) on a newly instantiated object to set its initial place and subscribing to the 'entered' event on the initial place.

Eventually we solved this as follows:

appointment:
    type: state_machine
    audit_trail:
        enabled: true
    marking_store:
        type: 'method'
        property: 'marking'
    supports:
        - Appointment
    initial_marking: UNKNOWN
    places:
        - UNKNOWN
        - SCHEDULED
        - RESCHEDULED
    transitions:
        TO_SCHEDULED:
            from: UNKNOWN
            to: SCHEDULED
        TO_RESCHEDULE:
            from: 
                - SCHEDULED
                - RESCHEDULED
            to: RESCHEDULED



// new object with blank state
$appointment = new Appointment();
$workflow = $this->workflowRegistry->get($appointment);
// set the marking to the initial state and transition to the correct state
$workflow->apply($appointment, 'TO_SCHEDULED');


public static function getSubscribedEvents(): array
{
    return [
        'workflow.patient_appointment.entered.SCHEDULED' => 'appointmentScheduled',
        'workflow.patient_appointment.entered.RESCHEDULED' => 'appointmentRescheduled'
    ];
}

My recommendations on how to update the documentation:

  • explicitly mention that 'initial_marking' is optional and that the first defined place will be used as the initial place by default.
  • explicitly mention that when entering the initial place, there is no 'entered' event dispatched
  • perhaps have an example of how the setup the states when the initial state should have an event.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy