PhoenixKit.Modules.Publishing.Groups (PhoenixKitPublishing v0.1.6)

Copy Markdown View Source

Group management functions for the Publishing module.

Handles creating, listing, updating, and removing publishing groups, as well as slug generation, type/mode normalization, and item naming.

Summary

Functions

Adds a new publishing group.

Gets a publishing group by slug.

Returns the configured post mode for a publishing group slug.

Looks up a publishing group name from its slug.

Returns all publishing groups from the database.

Lists groups filtered by status (e.g. 'active', 'trashed').

Lists trashed publishing groups.

Returns the preset content types with their default item names.

Removes a publishing group by slug.

Removes a publishing group by slug.

Restores a trashed publishing group.

Moves a publishing group to trash (soft-delete).

Updates a publishing group's display name and slug.

Returns the list of valid group type values.

Types

group()

@type group() :: map()

Functions

add_group(name, opts \\ [])

@spec add_group(String.t(), keyword() | map()) :: {:ok, group()} | {:error, atom()}

Adds a new publishing group.

Parameters

  • name - Display name for the group
  • opts - Keyword list or map with options:
    • :mode - Post mode: "timestamp" or "slug" (default: "timestamp")
    • :slug - Optional custom slug, auto-generated from name if nil
    • :type - Content type: "blog", "faq", "legal", or custom (default: "blog")
    • :item_singular - Singular name for items (default: based on type, e.g., "post")
    • :item_plural - Plural name for items (default: based on type, e.g., "posts")

Examples

iex> Groups.add_group("News")
{:ok, %{"name" => "News", "slug" => "news", "mode" => "timestamp", "type" => "blog", ...}}

iex> Groups.add_group("FAQ", type: "faq", mode: "slug")
{:ok, %{"name" => "FAQ", "slug" => "faq", "mode" => "slug", "type" => "faq", "item_singular" => "question", ...}}

iex> Groups.add_group("Recipes", type: "custom", item_singular: "recipe", item_plural: "recipes")
{:ok, %{"name" => "Recipes", ..., "item_singular" => "recipe", "item_plural" => "recipes"}}

get_group(slug)

@spec get_group(String.t()) :: {:ok, group()} | {:error, :not_found}

Gets a publishing group by slug.

Examples

iex> Groups.get_group("news")
{:ok, %{"name" => "News", "slug" => "news", ...}}

iex> Groups.get_group("nonexistent")
{:error, :not_found}

get_group_mode(group_slug)

@spec get_group_mode(String.t()) :: String.t()

Returns the configured post mode for a publishing group slug.

group_name(slug)

@spec group_name(String.t()) :: String.t() | nil

Looks up a publishing group name from its slug.

list_groups()

@spec list_groups() :: [group()]

Returns all publishing groups from the database.

list_groups(status)

@spec list_groups(String.t()) :: [group()]

Lists groups filtered by status (e.g. 'active', 'trashed').

list_trashed_groups()

@spec list_trashed_groups() :: [map()]

Lists trashed publishing groups.

preset_types()

@spec preset_types() :: [map()]

Returns the preset content types with their default item names.

remove_group(slug)

@spec remove_group(String.t()) :: {:ok, any()} | {:error, any()}

Removes a publishing group by slug.

remove_group(slug, opts)

@spec remove_group(
  String.t(),
  keyword()
) :: {:ok, any()} | {:error, any()}

Removes a publishing group by slug.

By default, refuses to delete groups that contain posts. Pass force: true to cascade-delete the group and all its posts.

restore_group(slug, opts \\ [])

@spec restore_group(String.t(), keyword() | map()) ::
  {:ok, String.t()} | {:error, any()}

Restores a trashed publishing group.

trash_group(slug, opts \\ [])

@spec trash_group(String.t(), keyword() | map()) ::
  {:ok, String.t()} | {:error, any()}

Moves a publishing group to trash (soft-delete).

Sets the group status to "trashed". The group and its posts remain in the database and can be restored. Trashed groups are hidden from list_groups/0.

update_group(slug, params, opts \\ [])

@spec update_group(String.t(), map() | keyword(), keyword() | map()) ::
  {:ok, group()} | {:error, atom()}

Updates a publishing group's display name and slug.

valid_types()

@spec valid_types() :: [String.t()]

Returns the list of valid group type values.