|  Developer
Updated on November 23, 2021

Events subscription

Plugin can be subscribed for module events (, , , …) using a method. When some module event happens, a subscribed script gets called with an appropriate event (or, which is the same, a plugin gets notified by this event) if this event passes specified events filter, if events filter omitted, a plugin will be notified about ALL module events. To block all events specify no filter rules: ( or )

A method returns an id () which identifies a subscription created by the method call. This id can be used with and methods.

  • At this moment a equals to a name of an event handling script passed to a method, so it’s possible to use a script name as a argument for methods requiring it.
Change subscription events filter rules

It’s possible to change (add, modify, remove) subscription’s events filter rules using a method. To specify a filter rule to modify/remove a rule is used (it should be specified during filter rule creation within a method). is an array of filter rules.

To add a rule, specify its (if this rule is going to be changed) and a rule body.

To modify a rule, specify its and a new rule body.

To remove a rule, specify its and set an field to or .

Examples:

This example removes a filter rule with an , modifies a rule with an and adds a new rule.

				
					[
  { 
    "id": "1",
    "event": ""
  },
  { 
    "id": "100500",
    "event": "the best event",
    "accepts": [
      {
        "id": 42
      }
    ]
  },
  { 
    "event": "event_1"
  },
]				
			
Format of an :
				
					{
  "exclude": "bool",
  "rules": [
    {
      "id": "event_id",
      "event": "event_name",
      "accepts": [
        {
          "some_id": 42,
          "some_name": {}
        },
        {
          "some_stuff": "the best stuff"
        }
      ]
    },
    {
      "event": "event_name_2",
    },
    ...
  ]
}				
			
fields type required description
exclude bool event filter rules policy
rules table(array) + table specifying event filter rules
rules[i].id string rule id (to change it in the future)
rules[i].event string + event name to match
rules[i].accepts table(array) event parameters to match

An event filter rules policy specifies how to treat event filter rules:

  • == : pass only events NON-matching ANY event filter rules
  • == (default): pass only events matching ANY event filter rules

Event matches a rule if:

  • == [ && ( == && == … && == ) || ( == && == … && == ) … || ( == && == … && == ) ]

== if && || &&

Examples of event filter rules:

Pass only and events:

				
					{
  "exclude": false,
  "rules": [
    {
      "event": "node_added",
    },
    {
      "event": "event_1",
    },
  ]
}				
			

Pass only events if they have ( and ) or ( and ) event data, events which have some date alongside with mention early, will pass too.

				
					{
  "rules": [
    {
      "event": "event_1",
      "accepts": [
        {
          "id": 42,
          "name": "the best name ever"
        },
        {
          "age": 100500,
          "city": {}
        }
      ]
    }
  ]
}				
			

Block only events and :

				
					{
  "exclude": true,
  "rules": [
    {
      "event": "event_1",
    },
    {
      "event": "event_2",
    },
  ]
}				
			

Block all events:

				
					{
  "exclude": false,
  "rules": []
}
  or
{
  "rules": []
}				
			
Format of a generic event:
				
					{
  "event": "string",
  ...
}				
			
fields type description
event string type of an event
data specific to the event
Example of a generic event:
				
					{
  "event": "the best event",
  "id": 42,
  "some_key": "some_value",
  "info": {
    "key_1": 100500,
    "key_2": "value_2"
  }
}