Events

The concept regarding the notification is being described in the Notifications page.

  • To dispatch notifications in the user account when something happens on a resource or a space they are following

  • To dispatch emails for the above notifications, if the user has not enabled the mail digest

  • To dispatch push notifications when the installation is active and the user has enabled them

  • To show the activity done by the user in the user’s account page

  • In admin panel to show the activity of other admins

  • To dispatch emails to admins when a resource or user is reported

  • To dispatch emails to users when an admin performs an action on the resource owned (like approving Proposal, accepting budgets etc )

Event classes are located in the app/events/decidim/<my_module> directory, and named: <my_resource>_event.rb.

# frozen_string_literal: true

# app/events/decidim/my_module/my_resource_event.rb
module Decidim
  module MyModule
    class MyResourceEvent < Decidim::Events::SimpleEvent
      # Defines a list of methods that will be used to translate the resource inside the event.
      i18n_attributes :example_resource_title

      # The name of the method can be 100% customized, but it must return a string.
      # the resource object used in the method body is the object that is being handled by the event.
      def example_resource_title
        translated_attribute(resource.title)
      end
    end
  end
end