Sha256: 8a87c3db76b714619e1a3f86d6e26634b81715fb85a47e880b5526688b04b009

Contents?: true

Size: 1.08 KB

Versions: 37

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Decidim
  module Events
    # This module is used to be included in event classes inheriting from SimpleEvent
    # whose resource has an in the "extra" options a user_group in the keyword :group.
    #
    # It adds the group_name, group_nickname, group_path and group_url to the i18n interpolations.
    module UserGroupEvent
      extend ActiveSupport::Concern

      included do
        i18n_attributes :group_name, :group_nickname, :group_path, :group_url

        def group_nickname
          group_presenter&.nickname.to_s
        end

        def group_name
          group_presenter&.name.to_s
        end

        def group_path
          group_presenter&.profile_path.to_s
        end

        def group_url
          group_presenter&.profile_url.to_s
        end

        def group_presenter
          return unless group

          @group_presenter ||= Decidim::UserGroupPresenter.new(group)
        end

        def group
          @group ||= Decidim::UserGroup.find_by(id: extra[:group_id]) if extra[:group_id]
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
decidim-core-0.26.8 lib/decidim/events/user_group_event.rb
decidim-core-0.27.4 lib/decidim/events/user_group_event.rb
decidim-core-0.27.3 lib/decidim/events/user_group_event.rb
decidim-core-0.26.7 lib/decidim/events/user_group_event.rb
decidim-core-0.26.5 lib/decidim/events/user_group_event.rb
decidim-core-0.27.2 lib/decidim/events/user_group_event.rb
decidim-core-0.27.1 lib/decidim/events/user_group_event.rb
decidim-core-0.26.4 lib/decidim/events/user_group_event.rb
decidim-core-0.27.0 lib/decidim/events/user_group_event.rb
decidim-core-0.26.3 lib/decidim/events/user_group_event.rb
decidim-core-0.27.0.rc2 lib/decidim/events/user_group_event.rb
decidim-core-0.27.0.rc1 lib/decidim/events/user_group_event.rb
decidim-core-0.26.2 lib/decidim/events/user_group_event.rb
decidim-core-0.26.1 lib/decidim/events/user_group_event.rb
decidim-core-0.26.0 lib/decidim/events/user_group_event.rb
decidim-core-0.26.0.rc2 lib/decidim/events/user_group_event.rb
decidim-core-0.26.0.rc1 lib/decidim/events/user_group_event.rb