Orchard Workflows

Gepostet von Patrick am 13.06.2022

Orchard CMS

Orchard Workflows

We’re building an increasing number of sites using Orchard Core as the content management system, which means that the features and requirements are becoming more complex and demanding. If you want to introduce a new business rule, a simple option is to implement this feature using custom code. But that comes with the disadvantage that changes can only be made through code and new deployment.

Orchard Core offers an excellent feature called “Workflows”. Workflows are used to implement business rules using flowchart diagrams. Within this feature, Orchard uses the concepts of “Events”, which trigger the start of the workflow, and “Tasks”, which are the steps that are executed. The workflow feature needs to be enabled in the Configuration > Features section in Orchard.

There are a number of built-in events within Orchard. For example, there are events to handle the content management itself, such as content creation, deletion or publication. There are also events available to handle user management (create, delete, update, login). A very useful one is the HTTP Request event, used to build simple REST APIs, which generates a specific URL that can be called from third-party apps or the CMS itself using any HTTP method (GET, POST, PUT, DELETE, PATCH, OPTIONS).

Once the event triggers the workflow, the tasks come into play. These are designed to model the business rules. In the CMS, various tasks already exist to enable content to be created, updated, published or deleted. Additionally, there are HTTP-based tasks, which can be used to redirect the user, write a specific HTTP response or call a third-party app via HTTP. The CMS also contains tasks to control workflows, such as ForEach, if/else, Fork and Loop logics. Messaging features, such as email, are also included. There are additional tasks for data validation, user-centric actions and primitives for logging or setting properties.

The following example in this blog exposes an HTTP endpoint that can be called by a form. To keep things simple, we haven’t included any validation in the API itself – we just take the data from the API and send it by email. At the end, the user will be redirected to the confirmation page.

The steps in detail:

  1. http-form: This is an HTTP Request event that exposes a URL that can be called directly by the form published on the website;
  2. Once the URL is called, the Email task is called. It takes the data from the form, where Orchard has included helpers to access the data directly using the Request.Form.MyFieldName syntax. This task sends an email to the website owners;
  3. Finally, there is an HTTP Redirect task, which will redirect the user to the confirmation page.