Automation with ECA¶
Use sites in ECA models: test for the hub, load an item's or a user's sites into tokens, and run actions as another site.
Needs Sites ECA
Part of Sites ECA.
composer require drupal/sites_eca
drush en sites_eca
Composer brings ECA along. Models are built in an ECA modeller; the ECA documentation lists them.
What it adds¶
Sites ECA adds no events: a model starts from any ECA event, like Update content entity, and uses these plugins from the Sites category.
| Plugin | Kind | Does |
|---|---|---|
| Current site is the hub | Condition | True when the request runs on the hub. Can be negated. |
| Sites: determine entity sites | Action | Writes an item's canonical site to one token and all its sites to another. |
| Sites: load user sites | Action | Writes the sites where a user may add, remove or manage content to a token. |
| Sites: switch current site | Action | Makes a site the current site for the actions that follow it; then the previous site is current again. |
Their settings:
- Sites: determine entity sites: Name of entity token (empty: the
entity of the form the event belongs to), Token name: canonical site
(default
canonical_site) and Token name: sites (defaultsites). Leave a token name empty to skip it. - Sites: load user sites: Name of user token (empty: the current
user), Operation (Add, Remove or Manage) and Result token
name (default
user_sites). - Sites: switch current site: Site ID, tokens allowed. A site ID that does not exist is refused on save; one that resolves to no site at run time switches nothing.
A site in a token carries its ID and its settings,
like [canonical_site:hostname]. Sensitive settings, like the password
protection credentials, read (redacted).
Example¶
Mail the editorial team when a page changes, naming the page's site:
- Event Update content entity, for the Basic page type.
- Action Sites: determine entity sites, with Name of entity token
entity. - Action Send email, with the subject
[entity:title] changed on [canonical_site:title].