Action: Perform tasks on specific events triggered within the system

The Action module provides tasks that can be executed by the website such as unpublishing content, sending an email, or banning a user. Other modules can fire these actions when certain system events happen; for example, when a new post is added or when a user logs in. Modules may also provide additional actions. Action is a core module in Drupal 8 and later.

To configure actions, navigate to /admin/config/system/actions.

There are two types of actions: simple and advanced. Simple actions do not require any additional configuration and are listed here automatically. Advanced actions need to be created and configured before they can be used because they have options that need to be specified; for example, sending an e-mail to a specified address or unpublishing content containing certain words.

Configuring actions

From the Actions page you can configure or create actions. To create an advanced action, select the action from the drop-down list in the advanced action section and click the Create button.

Declaring action functions

Action functions are declared by modules by implementing hook_action_info(). Modules can cause action functions to run by calling actions_do().

Each action function takes two to four arguments:

  • - $entity: The object that the action acts on, such as a node, comment, or user

Rules Core

An Overview:

The Rules module allows site administrators to define conditionally executed actions based on occurring event conditions. You can read more about this topic at Wikipedia's ECA-rules article). This can be a complicated subject at first, but the most important take away message going into it is that Rules opens opportunities for site builders and developers to extend Drupal in ways not possible before.

Events

Rules allows you to configure actions to be fired on various events. For example, if a user is creating a new content, the event "Content has been created" occurs. So Rules allows you to react to this event by firing actions. There are a lot of different events available, and contributed modules can even introduce new events. Some more examples of events would be

  • a user has logged in
  • content has been viewed
  • a new comment has been saved
  • ...

Rules events have nothing to do with calendars. ;)

Actions

Rules provides various actions, which let you actually do something. Some examples of actions are

  • send an email to a user
  • unpublish content
  • delete a comment
  • ...

So the combination of Events and Actions could read like any of these examples:

  • When "a user has logged in", "send an email to a user".
Subscribe with RSS Subscribe to RSS - trigger