Problem/Motivation
Right now, recipes have no way to check ahead of time if they will be able to apply to the current site. They just sally forth and potentially hit a scary exception, which may or may not be helpful.
Proposed resolution
Drupal already has a mechanism for checking preconditions: condition plugins!
Recipes should leverage these by letting them be configured declaratively in recipe.yml
. For example:
preconditions:
configValueIs:
- 'system.theme:default': olivero
summary: 'The front-end theme must be Olivero.'
- 'system.site:mail': 'dukat@terok.nor'
negate: true
summary: 'Emails from Drupal cannot be coming from Gul Dukat.'
Each set of conditions is handled by a particular plugin (configValueIs
, in this case). Each plugin can accept multiple conditions, and each of those conditions may or may not be negated. Each may also be summarized in a human-friendly way so that the recipe can provide useful feedback if the condition doesn't check out.
The one rule is that all defined conditions must pass, or the recipe will refuse to apply. To use the technical jargon, all conditions are always logically ANDed together. There is no logical OR. If you want to do fancy-pants logic, you need a custom condition plugin.
This also opens the door to adding a --check
(or similar) option to the recipe
console command, so you can know if a recipe is compatible with your site. Project Browser could also benefit from this.
Remaining tasks
Make it so with tests.
API changes
Recipes will gain new declarative functionality, but condition plugins are a long-standing part of core so this is not going to introduce any API changes or additions.