Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In some cases a field for storing a transition is required. Such case is the need to configure the desired transition that a license (commerce_license) should go through when an order is placed (should it move to pending state, requiring validation, or fully activate?). The attached patch provides a field type for that, with the option to restrict possible values by from/to states.
Comment | File | Size | Author |
---|---|---|---|
#2 | 2911807-transition-field-type-2.patch | 9.02 KB | krystalcode |
|
Comments
Comment #2
krystalcode CreditAttribution: krystalcode at Acro Commerce commentedComment #3
bojanz CreditAttribution: bojanz commentedI don't understand the purpose of this issue / patch.
Is there a related license issue that explains the use case?
I expected it to allow me to select a workflow and then a transition, but instead it's storing actual form/to states, but how would that be used?
In addition to that, we have no tests.
Comment #4
krystalcode CreditAttribution: krystalcode at Acro Commerce commentedIt's been a while but from what I recall: when you place an order that contains a license, the license undergoes a transition. Depending on the store needs and the nature of the license it may undergo a different transition e.g. in some stores the license is fully activated as soon as the order is placed, while in other stores or other license types in the same store it moves to a state that requires verification.
The license configuration, including which transition it should go through when the order is placed, is stored on the purchased product variation. It is not good enough to store the end state because there may be different transitions leading to the same state. We therefore need to store the transition itself.
I hope it makes sense. Not sure the module architecture has remained the same.
Comment #5
krystalcode CreditAttribution: krystalcode at Acro Commerce commentedIt stores the transition as the value of the field.
The from/to states and the workflow are field settings, not stored values, and they allow the developer to restrict which transitions will be available for selection as field values.
There may be multiple workflows defined for the entity, with the workflow field setting the developer can chose the transitions of which workflow will be available for selection.
The `from/to` field settings allow further restricting the transitions available for selection. In the commerce license example, we know that the license will always be at, say, the Draft state at the moment the order is being place. It makes sense to limit selection to transitions with Draft as their `from` state, both to only present options that make sense to the store manager and to eliminate the possibility of mistakenly selecting a transition that will cause an error.