Only the stack owner, the administrator, or the developer can define the Publish Rules. We have discussed briefly what Publish Rules are, with examples. Publish Rules are made up of two parts: Parameters and Conditions.
For every publish rule, you need to define the following parameters:
- Branch(es): The branch(es) to which the publish rule will be applied
- Environment: The environment for which the publish rule will be applicable
- Content type: The content type to which the publish rule will be applied
- Action: Whether the publishing rule is for publish or unpublish (or both) action
- Language: The language for which the rule is applicable
Once you define the parameters, define a condition.
Note: You can use either one or both of the following conditions for your publishing rule.
- Approver: Use this condition if you want to add an approver to all the entries that are being published or unpublished. Add the user(s)/role(s) who should be authorized to approve the publishing or unpublishing of an entry.
For example, if you assign “John Smith” as the approver, every entry that is sent for publishing or unpublishing (and meets the required parameters), will go to John Smith for approval. The entry cannot be published or unpublished unless John approves it.
And, if you assign a role, let's say “Content Approver,” as the approver, every entry that is sent for publishing or unpublishing and meets the required parameters will go to every user who has been assigned this role for approval. The entry cannot be published or unpublished unless any one of the users who is assigned the “Content Approver” role approves it. - Stage: Use this condition if you want to allow publishing or unpublishing of an entry only if it has reached a certain workflow stage.
When this condition is defined, an entry cannot be published or unpublished unless it reaches the defined stage while creating content. For example, if you have selected Complete here, an entry (that matches the parameters defined above) cannot be published unless it reaches the Complete stage.
Key points to remember:
- Setting up publish rules is optional.
- You need to choose at least one condition (Approver(s) or Stage) for a publishing rule. You can choose both, if required, but at least one is mandatory.
- A publishing rule with Approver(s) as the condition can work independently of workflows. This means that you can add one or more publish rules (with Approver(s) under conditions) even if you have not added any workflows for your stack. However, in order to use the Stage condition for your publishing rule, you will need at least one workflow.
Once a rule is in place, whenever a content manager attempts to publish or unpublish an entry on the specified environment, Contentstack will either send the entry for approval (if approvers are added as a condition), or check if the entry has reached the specified stage (if stage is added as a condition). It will then return the response accordingly.
To get further understanding on Publish rule components, make sure you read our documents mentioned in our “More articles”section.