State Machine
Provides code-driven workflow functionality. A workflow is a set of states and transitions that an entity goes through during its lifecycle. A transition represents a one-way link between two states and has its own label.Drupal 8
Workflows and workflow groups are plugins defined in YAML, similar to menu links. The current state is stored in a special field type (StateItem), which references the used workflow, and acts as a state machine. It has an API for getting the allowed transitions: <?php $order_state = $order->getState(); print $order_state->value; // fulfillment // Get the allowed transitions for the current state. $transitions = $order_state->getTransitions(); // All transitions have a translatable label that can be shown in the UI (great for action buttons) print_r($transitions['completed']->getLabel()); // Same as $order_state->value = 'completed'; $order_state->applyTransition($transitions['complete']); ?> An entity can have multiple workflows, each in its own state field. An order might have checkout and payment workflows. A node might have legal and marketing workflows. Workflow groups are used to group workflows used for the same purpose (e.g. payment workflows).See the README for a full architecture overview.
Drupal 7
The State Flow submodule provides a base implementation of the State Machine class. It provides a base workflow as a base plugin. Custom plugins should use State Flow as a model when:- Adding new states
- Adding new events
- Rules: Hook a condition into a event transition
- Views: Exposes defined states, revision information, and timestamps
7.x-2.x
- Extend State Flow by hook_state_flow_machine_type_alter() instead of variable_set
- Bulk revision editing
- Workflow scheduling. Requires Date_Popup.
- Easily implement conditions to allow workflow to be ignored