GithubHelp home page GithubHelp logo

steveoliver / state_machine Goto Github PK

View Code? Open in Web Editor NEW

This project forked from joshuataylor/commerce_workflow

0.0 2.0 0.0 72 KB

Official mirror of the drupal.org module, 8.x-1.x branch.

Home Page: https://drupal.org/project/state_machine

PHP 100.00%

state_machine's Introduction

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. The current state of a workflow is stored in a state field, which provides an API for getting and applying transitions. 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).

Architecture

Workflow and WorkflowGroup are plugins defined in YAML, similar to menu links. This leaves room for a future entity-based UI.

Example yourmodule.workflow_groups.yml:

order:
  label: Order
  entity_type: commerce_order

Groups can also override the default workflow class, for more advanced use cases.

Example yourmodule.workflows.yml:

default:
  id: default
  label: Default
  group: order
  states:
    new:
      label: New
    fulfillment:
      label: Fulfilment
    completed:
      label: Completed
    canceled:
      label: Canceled
  transitions:
    create:
      label: Create
      from: [new]
      to:   fulfillment
    fulfill:
      label: Fulfill
      from: [fulfillment]
      to: completed
    cancel:
      label: Cancel
      from: [new, fulfillment]
      to:   canceled

Transitions can be further restricted by guards, which are implemented as tagged services:

  mymodule.fulfillment_guard:
    class: Drupal\mymodule\Guard\FulfillmentGuard
    tags:
      - { name: state_machine.guard, group: order }

The group argument allows the guard factory to only instantiate the guards relevant to a specific workflow group.

The current state is stored in a StateItem field. A field setting specifies the used workflow, or a value callback that allows the workflow to be resolved at runtime (checkout workflow based on the used plugin, etc. A validator is provided that ensures that the specified state is valid (exists in the workflow and is in the allowed transitions).

Currently uses only the options_select widget. A dropbutton node-like widget could be provided, but was initially omitted becase it only makes sense for the main entity workflow, which nodes already have (published status), while Commerce is pursuing a different UX.

A formatter will be provided that outputs a form with the allowed transitions, allowing workflow changes to happen outside of the edit form.

Credits

Initial code by Pedro Cambra.

Inspired by https://github.com/winzou/state-machine

state_machine's People

Contributors

bojanz avatar dawehner avatar artusamak avatar gozoo avatar

Watchers

Steve Oliver avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.