Sha256: d67d7deaf090a6b624bfda22730a2ba02709502e95ff26e156e01689e3602b5a

Contents?: true

Size: 1.03 KB

Versions: 9

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Alchemy
  module Admin
    module CurrentLanguage
      extend ActiveSupport::Concern

      included do
        # This needs to happen before BaseController#current_alchemy_site sets the session value.
        prepend_before_action :clear_current_language_from_session, if: :switching_site?, only: :index
        before_action :load_current_language
      end

      private

      def switching_site?
        params[:site_id].present? && (params[:site_id] != session[:alchemy_site_id]&.to_s)
      end

      def clear_current_language_from_session
        session.delete(:alchemy_language_id)
      end

      def load_current_language
        @current_language = if session[:alchemy_language_id].present?
          set_alchemy_language(session[:alchemy_language_id])
        else
          Current.language
        end
        if @current_language.nil?
          flash[:warning] = Alchemy.t("Please create a language first.")
          redirect_to admin_languages_path
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
alchemy_cms-7.3.4 app/controllers/concerns/alchemy/admin/current_language.rb
alchemy_cms-7.3.3 app/controllers/concerns/alchemy/admin/current_language.rb
alchemy_cms-7.3.2 app/controllers/concerns/alchemy/admin/current_language.rb
alchemy_cms-7.2.7 app/controllers/concerns/alchemy/admin/current_language.rb
alchemy_cms-7.3.1 app/controllers/concerns/alchemy/admin/current_language.rb
alchemy_cms-7.3.0 app/controllers/concerns/alchemy/admin/current_language.rb
alchemy_cms-7.2.6 app/controllers/concerns/alchemy/admin/current_language.rb
alchemy_cms-7.2.5 app/controllers/concerns/alchemy/admin/current_language.rb
alchemy_cms-7.2.4 app/controllers/concerns/alchemy/admin/current_language.rb