Workflows: Pattern: policy filter
Pattern: policy filter
Section titled “Pattern: policy filter”Policy workflows constrain which resources a user may access. They usually start with event/policy and add one or more query/where elements.
{ "identifier": "ProjectAccessPolicy", "title": "Project access policy", "async": false, "entry": "projectPolicy", "elements": [ { "name": "projectPolicy", "type": "event/policy", "options": { "module": "projects", "roles": ["employee"], "operations": ["read", "update"], "allow": ["admin", "manager"], "roleKey": "slug" }, "to": { "default": { "whereAssigned": ["default"] } } }, { "name": "whereAssigned", "type": "query/where", "options": { "where": [ [ { "left": { "type": "field", "value": "assigned_users.id" }, "operator": "=", "right": { "type": "recipe", "value": "user().id" } } ] ] } } ]}See Policies and Access before writing policy workflows; small mistakes can expose too much or hide too much.
Pattern: export or PDF flow
Section titled “Pattern: export or PDF flow”PDF export flows commonly write a file with action/export and return it to the browser with action/viewFile. The export action uses one view whose Twig blocks supply header, content, footer and optional setup. See PDF export.
{ "name": "exportReportPdf", "type": "action/export", "options": { "type": "pdf", "filename": "project-report.pdf", "view": "reports.project_summary", "store_module": "files", "view_module": "views", "view_data": { ".recipe": "{\"project\": $project, \"items\": $items}" } }, "to": { "default": { "viewReportPdf": ["default"] } }}{ "name": "viewReportPdf", "type": "action/viewFile"}Keep direct file responses synchronous because action/viewFile returns an HTTP response. For large batch exports, start an async workflow, store the generated file, and notify the user when it is ready. See PDF Export Workflow for the focused version of this pattern.
Pattern: run another workflow
Section titled “Pattern: run another workflow”Use action/run when one workflow coordinates another workflow. This keeps the caller small and lets the called workflow be tested independently.
{ "name": "startPublishJob", "type": "action/run", "options": { "workflow": "PublishProject", "async": true, "scope": true, "input": { "project": "$project" } }}Set scope to true when the child workflow should receive an explicit context. Pass only the variables it needs through input. Use in when the called workflow should receive a specific default input resource.
Checklist
Section titled “Checklist”- The workflow name describes a business outcome.
- The
entryelement exists and matches the intended trigger. - Every branch that can fail or be empty has an intentional path.
- UI response workflows are synchronous.
- Long jobs are asynchronous and report progress.
- Saved resources are created with
source/new, filled withop/set, and persisted withaction/save. - Examples, labels, and notifications do not expose customer, company, domain, or infrastructure details.
- Behavior is covered by workflow tests where the outcome matters.