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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

krystalcode created an issue. See original summary.

krystalcode’s picture

Status: Active » Needs review
FileSize
9.02 KB
bojanz’s picture

Status: Needs review » Needs work

I 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.

krystalcode’s picture

It'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.

krystalcode’s picture

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?

It 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.