Behaviour for PhoenixKit feature modules (internal and external).
Any module that implements this behaviour can register itself with PhoenixKit's tab registry, permission system, supervisor tree, and route system.
Usage
defmodule PhoenixKitHelloWorld do
use PhoenixKit.Module
@impl true
def module_key, do: "hello_world"
@impl true
def module_name, do: "Hello World"
@impl true
def enabled?, do: PhoenixKit.Settings.get_boolean_setting("hello_world_enabled", false)
@impl true
def enable_system do
PhoenixKit.Settings.update_boolean_setting_with_module("hello_world_enabled", true, "hello_world")
end
@impl true
def disable_system do
PhoenixKit.Settings.update_boolean_setting_with_module("hello_world_enabled", false, "hello_world")
end
@impl true
def permission_metadata do
%{
key: "hello_world",
label: "Hello World",
icon: "hero-hand-raised",
description: "A demo module"
}
end
@impl true
def admin_tabs do
[%PhoenixKit.Dashboard.Tab{
id: :admin_hello_world,
label: "Hello World",
icon: "hero-hand-raised",
path: "hello-world",
priority: 640,
level: :admin,
permission: "hello_world",
match: :prefix,
group: :admin_modules
}]
end
endRequired Callbacks
module_key/0- Unique string key (e.g.,"tickets","billing")module_name/0- Human-readable display nameenabled?/0- Whether the module is currently enabledenable_system/0- Enable the module system-widedisable_system/0- Disable the module system-wide
Optional Callbacks
All optional callbacks have sensible defaults provided by use PhoenixKit.Module:
get_config/0- Module stats/config map (default:%{enabled: enabled?()}). The default callsenabled?()which may hit the database. External modules with expensive config should override this with a cached implementation.permission_metadata/0- Permission key, label, icon, description (default:nil)admin_tabs/0- Admin navigation tabs (default:[])settings_tabs/0- Settings subtabs (default:[])user_dashboard_tabs/0- User-facing dashboard tabs (default:[])children/0- Supervisor child specs (default:[])route_module/0- Module providing route macros (default:nil)version/0- Module version string (default:"0.0.0")migration_module/0- Module implementing versioned migrations (default:nil). When set,mix phoenix_kit.updatewill automatically run this module's migrations alongside the core PhoenixKit migrations.required_integrations/0- Integration provider keys this module needs (default:[]). Used by the Integrations settings page to show relevant providers.integration_providers/0- Additional provider definitions this module contributes (default:[]).
Summary
Types
Permission metadata for the module
Callbacks
Returns the OTP app name for Tailwind CSS source scanning.
Types
Callbacks
@callback admin_tabs() :: [PhoenixKit.Dashboard.Tab.t()]
@callback children() :: [Supervisor.child_spec() | module() | {module(), term()}]
@callback css_sources() :: [atom()]
Returns the OTP app name for Tailwind CSS source scanning.
The installer uses this to generate the correct @source directive in the
parent app's app.css. It automatically resolves the right path based on
whether the dep is installed from Hex (deps/) or as a path dep.
Example
def css_sources, do: [:phoenix_kit_publishing]Headless modules (no templates) can skip this callback — the default is [].
@callback enabled?() :: boolean()
@callback get_config() :: map()
@callback integration_providers() :: [map()]
@callback migration_module() :: module() | nil
@callback module_key() :: String.t()
@callback module_name() :: String.t()
@callback permission_metadata() :: permission_meta() | nil
@callback required_integrations() :: [String.t()]
@callback required_modules() :: [String.t()]
@callback route_module() :: module() | nil
@callback settings_tabs() :: [PhoenixKit.Dashboard.Tab.t()]
@callback user_dashboard_tabs() :: [PhoenixKit.Dashboard.Tab.t()]
@callback version() :: String.t()